Skip to content

[SPARK-33560][test-maven][BUILD] Add "unused-import" check to Maven compilation process#30784

Closed
LuciferYang wants to merge 14 commits intoapache:masterfrom
LuciferYang:SPARK-33560
Closed

[SPARK-33560][test-maven][BUILD] Add "unused-import" check to Maven compilation process#30784
LuciferYang wants to merge 14 commits intoapache:masterfrom
LuciferYang:SPARK-33560

Conversation

@LuciferYang
Copy link
Contributor

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.

pom.xml Outdated
<compilerPlugin>
<groupId>com.github.ghik</groupId>
<artifactId>silencer-plugin_${scala.version}</artifactId>
<version>1.6.0</version>
Copy link
Contributor Author

@LuciferYang LuciferYang Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

image

@LuciferYang
Copy link
Contributor Author

cc @HyukjinKwon

@github-actions github-actions bot added the BUILD label Dec 15, 2020
@SparkQA
Copy link

SparkQA commented Dec 15, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37437/

@SparkQA
Copy link

SparkQA commented Dec 15, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37437/

pom.xml Outdated
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to repeat the version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, Address 36268b4 fix this

<recompileMode>incremental</recompileMode>
<useZincServer>true</useZincServer>
<args>
<arg>-unchecked</arg>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so the idea is we can't apply these to both 2.12 and 2.13? why not unchecked though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address be95a1b fix this

@SparkQA
Copy link

SparkQA commented Dec 15, 2020

Test build #132835 has finished for PR 30784 at commit c6d2926.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

Thank you @LuciferYang for tackling this in Maven too. @MaxGekk too FYI.

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37455/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37455/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Test build #132853 has finished for PR 30784 at commit 36268b4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use <!-- --> XML syntax for comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx~ Address e4b4e0f fix this

@HyukjinKwon HyukjinKwon changed the title [SPARK-33560][BUILD] Add "unused-import" check to Maven compilation process [SPARK-33560][test-maven][BUILD] Add "unused-import" check to Maven compilation process Dec 16, 2020
@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37464/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37461/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37464/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37461/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Test build #132881 has started for PR 30784 at commit dc58f8a.

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37483/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37483/

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Test build #132859 has finished for PR 30784 at commit 0ab5f23.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 16, 2020

Test build #132862 has finished for PR 30784 at commit e4b4e0f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

<recompileMode>incremental</recompileMode>
<useZincServer>true</useZincServer>
<args>
<arg>-unchecked</arg>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if neither is specified?

The extra args defined in scala-2.12 profile will not appended If not activated by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address 4fe256 changed a way to achieve the purpose, but still unsatisfactory :(

@SparkQA
Copy link

SparkQA commented Dec 17, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37560/

pom.xml Outdated
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration combine.self="override">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need combine.self="override" here or on just the children that are overridden?
(But yes this is what I was getting at)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about combine.self="override" on compilerPlugins, and leave it empty? does that not effectively remove the config in 2.13?

Copy link
Contributor Author

@LuciferYang LuciferYang Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address fcad7a4 move combine.self="override" on compilerPlugins and leave it empty. Maven can pass and wait GA sbt build

@LuciferYang LuciferYang marked this pull request as ready for review December 17, 2020 15:25
@SparkQA
Copy link

SparkQA commented Dec 17, 2020

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37560/

@SparkQA
Copy link

SparkQA commented Dec 17, 2020

Test build #132948 has finished for PR 30784 at commit e7b9e18.

  • This patch fails from timeout after a configured wait of 500m.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 17, 2020

Test build #132957 has finished for PR 30784 at commit be95a1b.

  • This patch fails SparkR unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 18, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37586/

@SparkQA
Copy link

SparkQA commented Dec 18, 2020

Test build #132986 has finished for PR 30784 at commit fcad7a4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 18, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/37586/

pom.xml Outdated
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<checkMultipleScalaVersions>true</checkMultipleScalaVersions>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK now do these settings need to be repeated? I'd have thought they don't now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address a8d432f remove redundant configs, seems only Scalac args and compilerPlugins are needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srowen Is there anything else that needs to be fixed? thx ~

@SparkQA
Copy link

SparkQA commented Dec 21, 2020

Test build #133124 has finished for PR 30784 at commit fe9d279.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Dec 21, 2020

Test build #133151 has finished for PR 30784 at commit fe9d279.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

<artifactId>scala-maven-plugin</artifactId>
<configuration>
<args>
<arg>-unchecked</arg>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK~ Will try it later. a little busy at the moment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for silencer-plugin, compilation will fail because this plugin does not exist in Scala 2.13
  • -Xfatal-warnings and -Ywarn-unused:imports: unused-imports check 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

@srowen
Copy link
Member

srowen commented Dec 23, 2020

OK that's fine if this is as simple as it can get.

@LuciferYang
Copy link
Contributor Author

thx~ @srowen

@srowen
Copy link
Member

srowen commented Dec 24, 2020

And should this be in 3.1 - is it probably necessary to build with Scala 2.13?

@LuciferYang
Copy link
Contributor Author

@srowen I think it should be merged to 3.1 too, need me to give an additional pr?

@HyukjinKwon
Copy link
Member

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.

@srowen srowen closed this in 37ae0a6 Dec 26, 2020
@srowen
Copy link
Member

srowen commented Dec 26, 2020

Merged to master/3.1

srowen pushed a commit that referenced this pull request Dec 26, 2020
…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>
@LuciferYang
Copy link
Contributor Author

thx ~ @srowen @HyukjinKwon

@LuciferYang LuciferYang deleted the SPARK-33560 branch June 6, 2022 03:45
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.

4 participants