Skip to content

Commit

Permalink
[MCOMPILER-544] don't add items to classpath that are not used for that
Browse files Browse the repository at this point in the history
Currently simply all kind of items are added to the classpath leading to
strange errors in the ECJ compiler plugin because it does not know how
to handle pom or other possible types.

This adds an additional check to see if the artifact handler actually
claims the itme should be put on the classpath,
  • Loading branch information
Christoph Läubrich authored and slawekjaranowski committed Oct 3, 2023
1 parent 8e748ec commit d138bd4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
Expand Up @@ -151,6 +151,7 @@ public class CompilerMojo extends AbstractCompilerMojo {

private Map<String, JavaModuleDescriptor> pathElements;

@Override
protected List<String> getCompileSourceRoots() {
return compileSourceRoots;
}
Expand All @@ -170,6 +171,7 @@ protected Map<String, JavaModuleDescriptor> getPathElements() {
return pathElements;
}

@Override
protected File getOutputDirectory() {
File dir;
if (!multiReleaseOutput) {
Expand All @@ -180,6 +182,7 @@ protected File getOutputDirectory() {
return dir;
}

@Override
public void execute() throws MojoExecutionException, CompilationFailureException {
if (skipMain) {
getLog().info("Not compiling main sources");
Expand Down Expand Up @@ -344,11 +347,14 @@ private List<File> getCompileClasspathElements(MavenProject project) {
list.add(new File(project.getBuild().getOutputDirectory()));

for (Artifact a : project.getArtifacts()) {
list.add(a.getFile());
if (a.getArtifactHandler().isAddedToClasspath()) {
list.add(a.getFile());
}
}
return list;
}

@Override
protected SourceInclusionScanner getSourceInclusionScanner(int staleMillis) {
if (includes.isEmpty() && excludes.isEmpty() && incrementalExcludes.isEmpty()) {
return new StaleSourceScanner(staleMillis);
Expand All @@ -363,6 +369,7 @@ protected SourceInclusionScanner getSourceInclusionScanner(int staleMillis) {
return new StaleSourceScanner(staleMillis, includes, excludesIncr);
}

@Override
protected SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding) {
// it's not defined if we get the ending with or without the dot '.'
String defaultIncludePattern = "**/*" + (inputFileEnding.startsWith(".") ? "" : ".") + inputFileEnding;
Expand All @@ -375,10 +382,12 @@ protected SourceInclusionScanner getSourceInclusionScanner(String inputFileEndin
return new SimpleSourceInclusionScanner(includes, excludesIncr);
}

@Override
protected String getSource() {
return source;
}

@Override
protected String getTarget() {
return target;
}
Expand All @@ -388,14 +397,17 @@ protected String getRelease() {
return release;
}

@Override
protected String getCompilerArgument() {
return compilerArgument;
}

@Override
protected Map<String, String> getCompilerArguments() {
return compilerArguments;
}

@Override
protected File getGeneratedSourcesDirectory() {
return generatedSourcesDirectory;
}
Expand Down

0 comments on commit d138bd4

Please sign in to comment.