Milwaukee Bucks All-Star guard Khris Middleton opted out of the final year of his contract and will officially become an unrestricted free agent.

Middleton passes on a one-year, $13 million deal for 2019-2020, but he and the Bucks are still discussing a new five-year contract to keep him in Milwaukee, ESPN reported Wednesday.

Middleton can sign a max value contract for five years with Milwaukee. Other teams can offer a four-year deal starting June 30.

A max contract worth more than $30 million per season could hamstring the Bucks against the cap and push Milwaukee into the luxury tax one year before Giannis Antetokounmpo can be offered a max extension.

The Bucks have a $19.5 million cap hold on Middleton that could help them retain their second-leading scorer from last season. However, multiple key role players, including Brook Lopez, Malcolm Brogdon and Nikola Mirotic, are also eligible for free agency.

Middleton, 27, had a career year averaging 18.3 points, 6.0 rebounds and 4.3 assists per game, the latter two marks setting career highs. He shot 37.8 percent from 3-point range on a career-high 6.2 attempts per game.

Bucks trade Snell

Tony Snell will be traded from the Bucks to the Detroit Pistons, who will also receive the 30th pick in the 2019 NBA Draft, when the moratorium on official transactions is lifted July 6.

The Bucks are looking to clear cap space as they begin the task of retaining the core of the roster that earned the Eastern Conference's top seed in the playoffs.

The trade saves Milwaukee more than $4 million, according to the Milwaukee Journal Sentinel, and clears from the books Snell's $12 million cap hit for the 2020-21 season.

Snell, 27, averaged 6.0 points, 2.1 rebounds and 17.6 minutes in 74 games (12 starts) in 2018-19. The 6-foot-7 wing shot 39.7 percent from 3-point range.

The Bucks could waive forward Jon Leuer, who will be sent back to Milwaukee in the deal agreed to Wednesday night, per ESPN.

Free agency will be a challenging stretch for Milwaukee with center Brook Lopez, All-Star guard Khris Middleton, point guard Malcolm Brogdon and 3-point specialist Nikola Mirotic eligible for new deals. Brogdon is a restricted free agent expected to draw high-level interest.