license-maven-plugin
license-maven-plugin copied to clipboard
Unable to use licenseResolver with classpath. LicenseRepository throws error with lack of "baseUrl"
This applies to all mojos using "org.codehaus.mojo.license.model.LicenseRepository" with classpath licenseResolver:
UpdateProjectLicenseMojo for reason : no baseURL defined in org.codehaus.mojo.license.model.LicenseRepository
[INFO] --- license-maven-plugin:2.0.0:update-project-license (update-project-license) @ cast-core --- [INFO] Adding a license repository jar:file:/C:/Users/hluth/.m2/repository/org/codehaus/mojo/license-maven-plugin/2.0.0/license-maven-plugin-2.0.0.jar!/META-INF/licenses [INFO] adding extra resolver classpath://io/testifi/license [INFO] Using classpath extraresolver: io/testifi/license [INFO] Adding a license repository null
The last line here logs the url : null , which will fail when using it and gets validated.
Ok after reading the code i forked that one for me and added some code to it. Dont think that the current "classpath" logic can access 3rd party dependencies, so i added:
else if ( extraResolver.startsWith( DEPENDENCY_PROTOCOL ) ) { extraResolver = extraResolver.substring( DEPENDENCY_PROTOCOL.length() ); LOG.info( "Using dependency extraresolver: {}", extraResolver ); Set<Artifact> cpEntries = mojo.getProject().getArtifacts(); LOG.info( "CP to scan:{}", cpEntries ); String[] groupAndArtifact = extraResolver.split( ":" ); String groupId = groupAndArtifact[0]; LOG.info( "groupId:{}", groupId ); String fileInside = extraResolver.split( "!" )[1]; String artifactId = groupAndArtifact[1].replace( fileInside, "" ).replace( "!", "" ); LOG.info( "artifactId:{}", artifactId ); LOG.info( "file in dependency:{}", fileInside ); for ( Artifact dep : cpEntries ) { if ( dep.getGroupId().equals( groupId ) && dep.getArtifactId().equals( artifactId ) ) { URLClassLoader cl = new URLClassLoader( new URL[] {dep.getFile().toURL()} ); URL fileInJar = cl.getResource( fileInside ); LOG.info( "found file:{}", fileInJar ); addRepository( fileInJar ); } } }
with property in pom: <license.licenseResolver>dependency:io.testifi.cast:cast-license!io/testifi/license</license.licenseResolver>