How do I get maven to download the platform.jar from the JNA project

Preston picture Preston · Jun 17, 2011 · Viewed 9.1k times · Source

I have the following POM entry

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>3.3.0</version>
</dependency>

When I build my project it downloads the following files:

  • jna-3.3.0.jar
  • jna-3.3.0.jar.sha1
  • jna-3.3.0.pom
  • jna-3.3.0.jar.sha1

If you visit the repository at http://download.java.net/maven/2/net/java/dev/jna/jna/3.3.0/ you can see there are numerous other files. Why isn't Maven downloading those other files?

If you open the jna-3.3.0.pom you see

<plugins>
  <!-- fake out maven and install the binary artifact -->
  <plugin>
    <groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
    <artifactId>maven-antrun-extended-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <!--<ant dir="." target="dist" />-->
            <attachArtifact file="dist/jna.jar" />
            <attachArtifact file="dist/platform.jar" classifier="platform" type="jar" />
            <attachArtifact file="dist/src-mvn.zip" classifier="sources" type="jar"/>
          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

I suspect the issue has something to do with the comment in the pom "fake out maven and install the binary artifact".

Answer

steve_barham picture steve_barham · Jun 21, 2011

If you add a second dependency to your project alongside the existing JNA dependency, with a classifier added, you should get the artifact added to your build.

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>3.3.0</version>
    <classifier>platform</classifier>
</dependency>

As you now have two artifacts from the same project, it would be sensible to extract the version element into a project level property so that updating it updates both:

<properties>
    <jna.version>3.3.0</jna.version>
</properties>

<dependencies>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>${jna.version}</version>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>${jna.version}</version>
        <classifier>platform</classifier>
    </dependency>
</dependencies>