Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-jar-plugin addClasspath scoping

Tags:

maven-2

Is there anyway to get the maven-jar-plugin to use scope when adding a classpath to a jar manifest? I have a project where I want to create 2 jars - runtime and test. The runtime jar should have a classpath of only the runtime dependencies. The test jar should have a classpath of the test dependencies. I have not been able to figure out how to do this. any ideas?

I am aware of MJAR-117, but this bug is over a year old - perhaps it has been resolved in a different JIRA?

like image 733
Paul Rowe Avatar asked Apr 08 '26 23:04

Paul Rowe


1 Answers

I don't think this is supported by the Maven Archiver (and MJAR-117 doesn't seem to get much traction). A possible workaround would be to provide (hard-coded) additional classpath entries when building the test-jar:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.2</version>
  <executions>
    <execution>
      <id>default-jar</id>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
          </manifest>
        </archive>
      </configuration>
    </execution>
    <execution>
      <id>default-test-jar</id>
      <phase>package</phase>
      <goals>
        <goal>test-jar</goal>
      </goals>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
          </manifest>
          <manifestEntries>
            <Class-Path>foo-1.0.jar bar-2.1.jar</Class-Path>
          </manifestEntries>
        </archive>
      </configuration>
    </execution>
  </executions>
</plugin>

I agree this is not ideal, you have to add things manually and this is error-prone. But it works.

You could maybe do something more dynamic with filtering and some antrun or groovy magic but this would definitely require more work.

Related question

  • Maven - how can I add an arbitrary classpath entry to a jar?
like image 105
Pascal Thivent Avatar answered Apr 21 '26 07:04

Pascal Thivent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!