1

I have dependencies with classifiers that contain placeholder property keys which can be overriden via system properties. The default property value for each classifier is empty. E.g.

<properties>
   <branch.classifier></branch.classifier>
</properties>

<dependency>
        <groupId>de.example</groupId>
        <artifactId>example</artifactId>
        <version>0.0.1</version>
        <classifier>${branch.classifier}</classifier>
</dependency>

Furthermore I want to unpack dependencies and copy some resources into a specific output directory.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.1</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeGroupIds>${project.groupId}</includeGroupIds>
                        <includeArtifactIds>my-dpendency</includeArtifactIds>
                        <includeClassifiers>${branch.classifier}</includeClassifiers>
                        <excludeTransitive>true</excludeTransitive>
                        <overWrite>true</overWrite>
                        <outputDirectory>${project.build.directory}/${project.artifactId}/conf</outputDirectory>
                        <includes>myfile.txt</includes>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
 </plugin>

However, the dependency plugin cannot unpack the file because it doesn't find it. I've debugged the plugin code and it seems that the comparison in the ProjectTrasivityFilter between maven's artifact object and the direct dependencies artifacts do not match, since maven handles empty classifiers as null values and the plugin sets the classifier to an empty string. Here is the problematic code:

public boolean artifactIsADirectDependency( Artifact artifact )
{
    for ( Artifact dependency : this.directDependencies )
    {
        if ( dependency.equals( artifact ) ) //condition returns false since "" not equals null
        {
            return true;
        }
    }
    return false;
}

Is this a bug in the plugin and does anyone have a workaround? If not how can I fix this issue?

Update: OK, I found a solution. If I set the plugin's excludeTransitive property to false it works. But still not sure whether this is a bug or not.

user35934
  • 374
  • 2
  • 13
  • Can you more in detail explain why you have a placeholder for a classifier ? What are you trying to achieve? Maybe a full working example project? – khmarbaise Jun 06 '18 at 15:28
  • I need to build same dependency snapshot versions with a different code base, i.e. different sofware revision from feature branches, to be able to deploy multiple app versions via jenkins. Each dependency in a feature branch is built with a classifier named after the branch name. When building the main application I pass the classifier as a system property for each dependency that is incompatible to the master branch so that it can pick it up at build time, otherwise I get compile errors.E.g.,the artifact `artifact-0.0.1-SNAPSHOT-mybranch.jar` is resolved by passing `-Dplaceholder=mybranch`. – user35934 Jun 06 '18 at 18:26
  • I recommend to use a different versions (like 1.0.0-FBABC-SNAPSHOT) instead of classifer... – khmarbaise Jun 08 '18 at 11:52

0 Answers0