apache / apache/maven-compiler-plugin
[MCOMPILER-408] CompileMojo resets project artifacts when used in verify phase
- Dominant language
- Java
- Stars
- 261
- Forks
- 191
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 8
Description
**[Benjamin Marwell](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=mampf86)** opened **[MCOMPILER-408](https://issues.apache.org/jira/browse/MCOMPILER-408?redirect=false)** and commented
## Problem Description / Setup
I tried to execute the google error-prone plugin in the compile phase, but was unsatisfied with the outcome. However, it seemed to be a perfect fit for the `verify` phase. Other plugins will also use the verify phase, e.g. checkstyle. I will also compile it to a different folder (which is `target/classes-errorprone`).
However, when using the CompileMojo, it will always call [projectArtifact.setFile(dir);|https://github.com/apache/maven-compiler-plugin/blob/master/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java#L189]. There is no possibility to override this.
I do think this is not always the wanted behaviour.
Now, when executing
```java
mvn clean verify -Perrorprone
```
the `ear` project will not find the `war` anymore, because the war had:
* Compile phase creating target/classes
* package phase, which set projectArtifact.setFile() to the `.war` file.
* verify phase, which set projectArtifact.setFile() back to `target/classes`.
## Reproducible
Always, see above.
## Workarounds
Do not execute verify+errorprone together with your main target phase and all reactor projects (e.g. including ear). But this will need two compile steps (one for packaging, anothero ne for error-prone).
## Expected behaviour
I can execute the maven-compiler-plugin with a compiler plugin like checkstyle in the verify phase without un-attaching any previous artifacts. At least as long as I compile into another directory.
## Actual behaviour
I cannot execute the compiler in the verify phase again using the `maven-compiler-plugin`, because it will reset my project artifacts.
## errorprone configuration
```java
errorprone
false
maven-compiler-plugin
errorprone
verify
compile
true
-XDcompilePolicy=simple
-Xplugin:ErrorProne
${plugin.errorprone.excluded.paths}
-XepDisableWarningsInGeneratedCode
${plugin.errorprone.additional.checks}
-d
${project.build.directory}/classes-ep
com.google.errorprone
error_prone_core
${dependency.errorprone.core.version}
true
```
Note: I use incrementalCompilation=true which behaves like non-incremental compilation due to a bug which is open since ever.
## Proposed sulutions
Either create a new goal (compile-only) or provide a switch to not invoke [projectArtifact.setFile(outputdir)|https://github.com/apache/maven-compiler-plugin/blob/master/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java#L189].
---
**Affects:** 3.8.0, 3.8.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java around the projectArtifact.setFile call at line 189, then reproduce the behavior with the provided mvn clean verify -Perrorprone configuration. Done means running the compiler plugin in verify without restoring the project artifact to the alternate output directory and without breaking the packaged artifact used by the ear project.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100