Skip to content

Conversation

@jackylee-ch
Copy link
Contributor

As mentioned in #14342, this PR introduces a compiler check for unused imports in Scala source code.
For Scala 2.13, unused imports will now be treated as errors.

@manuzhang
Copy link
Member

Is there a way to auto-fix unused imports?

@jackylee-ch
Copy link
Contributor Author

Is there a way to auto-fix unused imports?

Yes, we can use Scalafix to automatically remove unused imports.
I’ve already applied it to fix Scala code in #14311. We can add the ScalaFix in a separate PR.

@huaxingao
Copy link
Contributor

@jackylee-ch Thanks for the PR! With your fix, are we supposed to get error for unused imports? I quickly tried it out on my local (4.0_2.13), somehow I got warning instead.

@jackylee-ch
Copy link
Contributor Author

jackylee-ch commented Oct 16, 2025

Could you please share your build command? Have you configured the -DscalaVersion=2.13 parameter? Currently, this error typically occurs only when the Scala version is explicitly set to 2.13, as demonstrated in the example below.

./gradlew build -DflinkVersions= -DkafkaVersions= -DsparkVersions=4.0 -DscalaVersion=2.13 -x test -x integrationTest -x javaDoc

Task :iceberg-spark:iceberg-spark-extensions-4.0_2.13:compileScala

[Error] /Code/iceberg/spark/v4.0/spark-extensions/src/main/scala/org/apache/iceberg/spark/extensions/IcebergSparkSessionExtensions.scala:22:25: Unused import
Applicable -Wconf / @nowarn filters for this fatal warning: msg=, cat=unused-imports, site=org.apache.iceberg.spark.extensions
one error found

@huaxingao
Copy link
Contributor

@jackylee-ch Thanks for the clarification. LGTM

@jackylee-ch
Copy link
Contributor Author

@manuzhang @huaxingao Could we merge this PR now?
I’m planning to add ScalaFix to automatically remove unused imports, and it depends on the changes in current PR.

@huaxingao huaxingao merged commit b2ede55 into apache:main Oct 21, 2025
43 checks passed
@huaxingao
Copy link
Contributor

Thanks @jackylee-ch for the PR!

@jackylee-ch
Copy link
Contributor Author

Thanks for your reviewing. @manuzhang @huaxingao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants