From e72d4f9e337a5cd511ebb3c9474bebeab826d199 Mon Sep 17 00:00:00 2001 From: Andy Gumbrecht Date: Wed, 15 Jan 2020 15:18:15 +0100 Subject: [PATCH] Fix #139 - "Can't find license-maven-plugin" (#1) * Fix #139 - "Can't find license-maven-plugin" Use the PluginDescriptor. Most painful checkstyle. --- .travis.yml | 2 +- .../invoker.properties | 4 ++-- src/it/add-third-party-no-encoding/pom.xml | 13 ----------- .../license/AggregatorAddThirdPartyMojo.java | 22 ++++++++++++++++++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5470e28fb..75877b4da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: java -sudo: false +dist: trusty # Skip the Travis CI's default install command install: true diff --git a/src/it/add-third-party-no-encoding/invoker.properties b/src/it/add-third-party-no-encoding/invoker.properties index 09bf32591..a017991af 100644 --- a/src/it/add-third-party-no-encoding/invoker.properties +++ b/src/it/add-third-party-no-encoding/invoker.properties @@ -19,5 +19,5 @@ # . # #L% ### -invoker.goals=clean license:add-third-party -invoker.failureBehavior=fail-fast \ No newline at end of file +invoker.goals=clean ${project.groupId}:${project.artifactId}:${project.version}:add-third-party +invoker.failureBehavior=fail-fast diff --git a/src/it/add-third-party-no-encoding/pom.xml b/src/it/add-third-party-no-encoding/pom.xml index b6d0849a1..ca27c0635 100644 --- a/src/it/add-third-party-no-encoding/pom.xml +++ b/src/it/add-third-party-no-encoding/pom.xml @@ -45,19 +45,6 @@ 1.1.1 - - - - - - - org.codehaus.mojo - license-maven-plugin - @pom.version@ - - - - diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index e5a9acf53..2c5745e0c 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -33,6 +33,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -203,11 +204,30 @@ protected void doAction() } if ( groupId == null ) { - throw new IllegalStateException( "Can't find license-maven-plugin" ); + try + { + final PluginDescriptor pd = ( PluginDescriptor ) getPluginContext().get( "pluginDescriptor" ); + groupId = pd.getGroupId(); + artifactId = pd.getArtifactId(); + version = pd.getVersion(); + } + catch ( ClassCastException e ) + { + LOG.warn( "Failed to access PluginDescriptor", e ); + } + + if ( groupId == null ) + { + throw new IllegalStateException( "Failed to determine the license-maven-plugin artifact." + + + "Please add it to your parent POM." ); + } } String addThirdPartyRoleHint = groupId + ":" + artifactId + ":" + version + ":" + "add-third-party"; + LOG.info( "The default plugin hint is: " + addThirdPartyRoleHint ); + for ( MavenProject reactorProject : reactorProjects ) { if ( getProject().equals( reactorProject ) && !acceptPomPackaging )