javamavenmaven-jar-plugin

Maven: Simple classpathLayoutType is generating classpath similar to repository classpathLayoutType


I have a maven project which does the following:

When I added this code in my pom:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
      </manifest>
    </archive>
  </configuration>
</plugin>

It generated the following classpath in the jar:

Class-Path: lib/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar lib/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar

Obviously, this won't work because the classpath I need is as follows:

Class-Path: lib/commons-logging-1.1.1.jar lib/gson-2.8.2.jar

I went tothis page. According the documentation, what I need is the default classpathLayoutType of simple. But the classpath generated is in a repository layout. I even tried explicitly adding the below tag, but with no success.

<classpathLayoutType>simple</classpathLayoutType>

Why isn't the simple layout type not working?

EDIT

I have achieved what I need using custom layout type as follows:

<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>

Solution

  • What version of the maven archiver plugin are you using? Version 3.0.2 has a bug in ManifestConfiguration.class:

     public String getClasspathLayoutType()
     {
        return "simple".equals(this.classpathLayoutType) ? "repository" : this.classpathLayoutType;
      }
    

    The method for the ClasspathLayoutType is returning the wrong type. In maven archiver version 3.1.1 the bug is fixed, with layout types taking these possible values:

      public static final String CLASSPATH_LAYOUT_TYPE_SIMPLE = "simple";
      public static final String CLASSPATH_LAYOUT_TYPE_REPOSITORY = "repository";
      public static final String CLASSPATH_LAYOUT_TYPE_CUSTOM = "custom";
    

    Just try a higher fixed version.