[SPARK-33560][test-maven][BUILD] Add "unused-import" check to Maven compilation process#30784
[SPARK-33560][test-maven][BUILD] Add "unused-import" check to Maven compilation process#30784LuciferYang wants to merge 14 commits intoapache:masterfrom
Conversation
pom.xml
Outdated
| <compilerPlugin> | ||
| <groupId>com.github.ghik</groupId> | ||
| <artifactId>silencer-plugin_${scala.version}</artifactId> | ||
| <version>1.6.0</version> |
There was a problem hiding this comment.
Missing com.github.ghik:silencer-plugin_2.12.10:1.7.1 in Maven central repository
https://mvnrepository.com/artifact/com.github.ghik/silencer-plugin
|
cc @HyukjinKwon |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
pom.xml
Outdated
| <plugin> | ||
| <groupId>net.alchim31.maven</groupId> | ||
| <artifactId>scala-maven-plugin</artifactId> | ||
| <version>4.4.0</version> |
There was a problem hiding this comment.
You don't need to repeat the version
| <recompileMode>incremental</recompileMode> | ||
| <useZincServer>true</useZincServer> | ||
| <args> | ||
| <arg>-unchecked</arg> |
There was a problem hiding this comment.
OK so the idea is we can't apply these to both 2.12 and 2.13? why not unchecked though?
There was a problem hiding this comment.
With -unchecked, Scala 2.13 has compilation error as follow:
[ERROR] /spark-source/sql/core/src/test/scala/org/apache/spark/sql/streaming/sources/StreamingDataSourceV2Suite.scala:293: a pure expression does nothing in statement position
So Scala 2.12 use -unchecked, Scala 2.13 use -Wconf:cat=unchecked:wv
There was a problem hiding this comment.
Oh yeah, I recall this one has been around forever. But I'm pretty sure another change fixed something just like this by, well, just removing that dangling statement, which doesn't seem to do what it means to anyway. Maybe just fix that here directly rather than remove it?
|
Test build #132835 has finished for PR 30784 at commit
|
|
Thank you @LuciferYang for tackling this in Maven too. @MaxGekk too FYI. |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #132853 has finished for PR 30784 at commit
|
pom.xml
Outdated
| <arg>-Wconf:cat=scaladoc:wv</arg> | ||
| <arg>-Wconf:cat=unchecked:wv</arg> | ||
| <arg>-Wconf:cat=feature:wv</arg> | ||
| // TODO(SPARK-33499): Enable this option when Scala 2.12 is no longer supported. |
There was a problem hiding this comment.
I think we should use <!-- --> XML syntax for comments.
|
retest this please |
|
Kubernetes integration test starting |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Kubernetes integration test status failure |
|
Test build #132881 has started for PR 30784 at commit |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #132859 has finished for PR 30784 at commit
|
|
Test build #132862 has finished for PR 30784 at commit
|
| <recompileMode>incremental</recompileMode> | ||
| <useZincServer>true</useZincServer> | ||
| <args> | ||
| <arg>-unchecked</arg> |
There was a problem hiding this comment.
Oh yeah, I recall this one has been around forever. But I'm pretty sure another change fixed something just like this by, well, just removing that dangling statement, which doesn't seem to do what it means to anyway. Maybe just fix that here directly rather than remove it?
pom.xml
Outdated
|
|
||
| <profile> | ||
| <id>scala-2.12</id> | ||
| <activation> |
There was a problem hiding this comment.
This might be problematic - yes it should be the default, but this doesn't activate if any other profiles are activated, which may be surprising. What happens if neither is specified?
Generally the "2.12" configuration goes in the main POM and then is overridden for non-default profiles here. So if 2.13 needs different config, that's fine, but 2.12's config should be up top. If the problem is overwriting Maven config in a profile, I can show you how to do that.
There was a problem hiding this comment.
What happens if neither is specified?
The extra args defined in scala-2.12 profile will not appended If not activated by default.
There was a problem hiding this comment.
Generally the "2.12" configuration goes in the main POM and then is overridden for non-default profiles here. So if 2.13 needs different config, that's fine, but 2.12's config should be up top. If the problem is overwriting Maven config in a profile, I can show you how to do that.
I'll try to solve it first
There was a problem hiding this comment.
What I mean is: you put 2.12's config outside a profile. 2.13's config needs to replace it, and you can set this in the Maven XML a certain way to prevent it from just appending, instead making it replace. Otherwise these args won't be there at all for a 2.12 build where any profile is activated, without activating the 2.12 profile explicitly.
There was a problem hiding this comment.
Address 4fe256 changed a way to achieve the purpose, but still unsatisfactory :(
|
Kubernetes integration test starting |
pom.xml
Outdated
| <plugin> | ||
| <groupId>net.alchim31.maven</groupId> | ||
| <artifactId>scala-maven-plugin</artifactId> | ||
| <configuration combine.self="override"> |
There was a problem hiding this comment.
do you need combine.self="override" here or on just the children that are overridden?
(But yes this is what I was getting at)
There was a problem hiding this comment.
Yes, we need combine.self="override" here(merge is default value), merge and default will introduce additional configuration of compilerPlugins, but com.github.ghik:silencer-plugin_2.13.4:1.6.0 not exists in Maven central repository.
Or we can introduce com.github.ghik:silencer-plugin_2.13.4:1.7.1 manually and remove combine.self="override", although we don't really need i
There was a problem hiding this comment.
What about combine.self="override" on compilerPlugins, and leave it empty? does that not effectively remove the config in 2.13?
There was a problem hiding this comment.
Address fcad7a4 move combine.self="override" on compilerPlugins and leave it empty. Maven can pass and wait GA sbt build
|
Kubernetes integration test status failure |
|
Test build #132948 has finished for PR 30784 at commit
|
|
Test build #132957 has finished for PR 30784 at commit
|
|
Kubernetes integration test starting |
|
Test build #132986 has finished for PR 30784 at commit
|
|
Kubernetes integration test status success |
pom.xml
Outdated
| <artifactId>scala-maven-plugin</artifactId> | ||
| <configuration> | ||
| <scalaVersion>${scala.version}</scalaVersion> | ||
| <checkMultipleScalaVersions>true</checkMultipleScalaVersions> |
There was a problem hiding this comment.
OK now do these settings need to be repeated? I'd have thought they don't now.
There was a problem hiding this comment.
Address a8d432f remove redundant configs, seems only Scalac args and compilerPlugins are needed
There was a problem hiding this comment.
@srowen Is there anything else that needs to be fixed? thx ~
|
Test build #133124 has finished for PR 30784 at commit
|
|
retest this please |
|
Test build #133151 has finished for PR 30784 at commit
|
| <artifactId>scala-maven-plugin</artifactId> | ||
| <configuration> | ||
| <args> | ||
| <arg>-unchecked</arg> |
There was a problem hiding this comment.
Can the additional args just be appended in this config?
Or do you need to override them to remove some, thus, need to duplicate some compiler flags here?
This is going to be OK, just making sure we're keeping it as simple as we can.
There was a problem hiding this comment.
OK~ Will try it later. a little busy at the moment
There was a problem hiding this comment.
if we set <args combine.children="append"> in Scala 2.13, the effective pom will be
<args combine.children="append">
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-explaintypes</arg>
<arg>-target:jvm-1.8</arg>
<arg>-Xfatal-warnings</arg>
<arg>-Ywarn-unused:imports</arg>
<arg>-P:silencer:globalFilters=.*deprecated.*</arg>
<arg>-Wconf:cat=deprecation:wv,any:e</arg>
...
The are 3 flags shouldn't be in Scala 2.13
-P:silencer:globalFilters=.*deprecated.*: This is the compilation option forsilencer-plugin, compilation will fail because this plugin does not exist in Scala 2.13-Xfatal-warningsand-Ywarn-unused:imports:unused-importscheck not enabled in Scala 2.13, compilation will fail because scala.language.higherKinds no longer needs to be imported explicitly since Scala 2.13.1. Or need to add rules to suppress them.
So I think we may need to keep these duplicate flags here, or I haven't thought of an effective way yet
|
OK that's fine if this is as simple as it can get. |
|
thx~ @srowen |
|
And should this be in 3.1 - is it probably necessary to build with Scala 2.13? |
|
@srowen I think it should be merged to 3.1 too, need me to give an additional pr? |
|
Yes, merging it into branch-3.1 makes sense to me too. SPARK-33441 was for SBT only (It's fixed in branch-3.1). This is for Maven only. Should be easier to maintain if we merge this to branch-3.1. |
|
Merged to master/3.1 |
…ompilation process ### What changes were proposed in this pull request? Similar to SPARK-33441, this pr add `unused-import` check to Maven compilation process. After this pr `unused-import` will trigger Maven compilation error. For Scala 2.13 profile, this pr also left TODO(SPARK-33499) similar to SPARK-33441 because `scala.language.higherKinds` no longer needs to be imported explicitly since Scala 2.13.1 ### Why are the changes needed? Let Maven build also check for unused imports as compilation error. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass the Jenkins or GitHub Action - Local manual test:add an unused import intentionally to trigger maven compilation error. Closes #30784 from LuciferYang/SPARK-33560. Authored-by: yangjie01 <yangjie01@baidu.com> Signed-off-by: Sean Owen <srowen@gmail.com> (cherry picked from commit 37ae0a6) Signed-off-by: Sean Owen <srowen@gmail.com>
|
thx ~ @srowen @HyukjinKwon |

What changes were proposed in this pull request?
Similar to SPARK-33441, this pr add
unused-importcheck to Maven compilation process. After this prunused-importwill trigger Maven compilation error.For Scala 2.13 profile, this pr also left TODO(SPARK-33499) similar to SPARK-33441 because
scala.language.higherKindsno longer needs to be imported explicitly since Scala 2.13.1Why are the changes needed?
Let Maven build also check for unused imports as compilation error.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Pass the Jenkins or GitHub Action
Local manual test:add an unused import intentionally to trigger maven compilation error.