Details
Description
I have an issue with the WAR overlay and an empty classifier.
My use case:
I am including an overlay with a "dynamic" classifier value. Meaning that I set the classifier either to an empty value "" (equivalent to no classifier for an artifact) or to a "test" value if the corresponding profile is activated.
<dependencies> ... <dependency> <groupId>org.jahia.server</groupId> <artifactId>jahia-war</artifactId> <version>1.0</version> <classifier>${jahia.war.classifier}</classifier> <type>war</type> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <classifier>${jahia.war.classifier}</classifier> <overlays> <overlay> <groupId>org.jahia.server</groupId> <artifactId>jahia-war</artifactId> <classifier>${jahia.war.classifier}</classifier> <!-- files to exclude from the community --> <excludes> <exclude>gwt/**</exclude> </excludes> </overlay> </overlays> ...
When I launch "normal" build (mvn clean package), the value of my classifier property (${jahia.war.classifier}) is empty and I am getting the following error:
[INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] overlay[ id org.jahia.server:jahia-war] is not a dependency of the project. [INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.lifecycle.LifecycleExecutionException: overlay[ id org.jahia.server:jahia-war] is not a dependency of t he project. at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:55 6) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.jav a:387) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) Caused by: org.apache.maven.plugin.war.overlay.InvalidOverlayConfigurationException: overlay[ id org.jahia.server:jahia- war] is not a dependency of the project. at org.apache.maven.plugin.war.overlay.OverlayManager.getAssociatedArtifact(OverlayManager.java:223) at org.apache.maven.plugin.war.overlay.OverlayManager.initialize(OverlayManager.java:146) at org.apache.maven.plugin.war.overlay.OverlayManager.<init>(OverlayManager.java:76) at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:433) at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:394) at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:195) at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:157) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) ... 17 more
When I am debugging the execution of the code, I see that the comparison of the dependency artifact and the overlay in the
OverlayManager.compareOverlayWithArtifact(Overlay, Artifact) fails because the StringUtils.equals( overlay.getClassifier(), artifact.getClassifier()) results is false.
Looking at the values, I see the following:
overlay.getClassifier() == null
artifact.getClassifier() == ""
Thus comparing null to an empty string results in false.
Is there any chance in making this check more robust?
Thank you in advance!
Kind regards
Sergiy Shyrkov