Uploaded image for project: 'Maven JAR Plugin'
  1. Maven JAR Plugin
  2. MJAR-177

Empty string should be treated as default classifier

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4
    • 3.0.0
    • None
    • None

    Description

      I'm not an expert for Maven internals, but there seem to be subtle differences regarding empty properties. Sometimes they are set to null and sometimes they remain an empty string (""). The later causes an error when used as classifier

      This seems to be the problematic code from AbstratJarMojo.java:

      String classifier = getClassifier();
      if ( classifier != null ) // ERROR check for empty string
      {
          projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
      }
      else
      {
          getProject().getArtifact().setFile( jarFile );
      }
      

      The resulting error is

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project sample-project: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar failed: For artifact {org.example:sample-project:1.0.0-SNAPSHOT:jar}: An attached artifact must have a different ID than its corresponding main artifact. -> [Help 1]
      

      It's not easy to set a property to "" though as properties from XML will typically resolve to null but some plugins do. For example, it's possible to use gmaven-plugin to achieve this:

      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <executions>
          <execution>
            <id>artifact-classifier</id>
            <phase>initialize</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                project.properties['artifact.classifier'] = "";
              </source>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${maven-jar-plugin.version}</version>
        <inherited>true</inherited>
        <configuration>
          <classifier>${artifact.classifier}</classifier>
        </configuration>
      </plugin>
      

      Attachments

        Activity

          People

            khmarbaise Karl Heinz Marbaise
            sfussenegger Stefan Fussenegger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: