diff --git a/pom.xml b/pom.xml index 3f6c961c..a3f67462 100644 --- a/pom.xml +++ b/pom.xml @@ -189,6 +189,7 @@ under the License. test + org.apache.maven maven-compat ${mavenVersion} diff --git a/src/it/MCOMPILER-522-unresolvable-dependency/invoker.properties b/src/it/MCOMPILER-522-unresolvable-dependency/invoker.properties new file mode 100644 index 00000000..9e2dad8a --- /dev/null +++ b/src/it/MCOMPILER-522-unresolvable-dependency/invoker.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = compile +invoker.buildResult = failure diff --git a/src/it/MCOMPILER-522-unresolvable-dependency/pom.xml b/src/it/MCOMPILER-522-unresolvable-dependency/pom.xml new file mode 100644 index 00000000..0614cd0d --- /dev/null +++ b/src/it/MCOMPILER-522-unresolvable-dependency/pom.xml @@ -0,0 +1,52 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.compiler.it + mcompiler522-unresolvable-annotation-processor-depdendency + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + + org.issue.SimpleAnnotationProcessor + + + + org.apache.maven.plugins.compiler.it + annotation-processor-non-existing + 1.0-SNAPSHOT + + + + + + + diff --git a/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleAnnotation.java b/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleAnnotation.java new file mode 100644 index 00000000..0c79335f --- /dev/null +++ b/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleAnnotation.java @@ -0,0 +1,32 @@ +package org.apache.maven.plugins.compiler.it; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface SimpleAnnotation +{ + +} diff --git a/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleObject.java b/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleObject.java new file mode 100644 index 00000000..5d8760e5 --- /dev/null +++ b/src/it/MCOMPILER-522-unresolvable-dependency/src/main/java/org/apache.maven.plugins.compiler.it/SimpleObject.java @@ -0,0 +1,26 @@ +package org.apache.maven.plugins.compiler.it; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@SimpleAnnotation +public class SimpleObject +{ + +} diff --git a/src/it/MCOMPILER-522-unresolvable-dependency/verify.groovy b/src/it/MCOMPILER-522-unresolvable-dependency/verify.groovy new file mode 100644 index 00000000..d55928d7 --- /dev/null +++ b/src/it/MCOMPILER-522-unresolvable-dependency/verify.groovy @@ -0,0 +1,26 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +def logFile = new File( basedir, 'build.log' ) +assert logFile.exists() + +def buildLog = logFile.getText('UTF-8') +assert buildLog.contains ("Caused by: org.apache.maven.plugin.MojoExecutionException: " + + "Resolution of annotationProcessorPath dependencies failed: " + + "Could not find artifact org.apache.maven.plugins.compiler.it:annotation-processor-non-existing:jar:1.0-SNAPSHOT" ) diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index 8da9213b..2f837367 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -40,14 +40,8 @@ import java.util.Properties; import java.util.Set; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ResolutionErrorHandler; -import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; @@ -56,7 +50,6 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.shared.incremental.IncrementalBuildHelper; import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest; import org.apache.maven.shared.utils.ReaderFactory; @@ -83,6 +76,15 @@ import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; import org.codehaus.plexus.languages.java.version.JavaVersion; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.resolution.DependencyRequest; +import org.eclipse.aether.resolution.DependencyResult; +import org.eclipse.aether.util.artifact.JavaScopes; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -581,12 +583,6 @@ public abstract class AbstractCompilerMojo @Component private ArtifactHandlerManager artifactHandlerManager; - /** - * Throws an exception on artifact resolution errors. - */ - @Component - private ResolutionErrorHandler resolutionErrorHandler; - protected abstract SourceInclusionScanner getSourceInclusionScanner( int staleMillis ); protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding ); @@ -1814,29 +1810,26 @@ private List resolveProcessorPathEntries() ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( coord.getType() ); Artifact artifact = new DefaultArtifact( - coord.getGroupId(), - coord.getArtifactId(), - VersionRange.createFromVersionSpec( coord.getVersion() ), - Artifact.SCOPE_RUNTIME, - coord.getType(), - coord.getClassifier(), - handler, - false ); - - ArtifactResolutionRequest request = new ArtifactResolutionRequest() - .setArtifact( artifact ) - .setResolveRoot( true ) - .setResolveTransitively( true ) - .setLocalRepository( session.getLocalRepository() ) - .setRemoteRepositories( project.getRemoteArtifactRepositories() ); - - ArtifactResolutionResult resolutionResult = repositorySystem.resolve( request ); - - resolutionErrorHandler.throwErrors( request, resolutionResult ); - - for ( Artifact resolved : resolutionResult.getArtifacts() ) + coord.getGroupId(), + coord.getArtifactId(), + coord.getClassifier(), + handler.getExtension(), + coord.getVersion() + ); + + CollectRequest collectRequest = new CollectRequest( new Dependency( artifact, JavaScopes.RUNTIME ), + project.getRemoteProjectRepositories() ); + DependencyRequest dependencyRequest = new DependencyRequest(); + dependencyRequest.setCollectRequest( collectRequest ); + DependencyResult dependencyResult = repositorySystem.resolveDependencies( + session.getRepositorySession(), dependencyRequest ); + + for ( ArtifactResult resolved : dependencyResult.getArtifactResults() ) { - elements.add( resolved.getFile().getAbsolutePath() ); + if ( resolved.getArtifact() != null && resolved.getArtifact().getFile() != null ) + { + elements.add( resolved.getArtifact().getFile().getAbsolutePath() ); + } } } return new ArrayList<>( elements );