Maven-jar-plugin addClasspath scoping

In any case, to force maven-jar-plugin to use scope when adding classpath to jar manifest? I have a project where I want to create 2 jars - runtime and test. The runtime bank should only have a classpath of runtime dependencies. The test bank must have a path to the test dependency classes. I could not figure out how to do this. any ideas?

I know MJAR-117 , but this error is more than a year old - perhaps it was resolved in another JIRA?

+3
source share
3 answers

I do not think this is supported by the Maven Archiver (and the MJAR-117 does not seem to be very burdensome). A possible workaround would be to provide (hard-coded) additional class path entries when building 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 that this is not ideal, you need to add things manually, and this is error prone. But it does work.

Perhaps you could do something more dynamic with filtering and some antrun or groovy magic, but that would certainly require more work.

Related question

+4
source

, ​​ . , , . , maven profiles

:

<profile>
  <id>test</id>
  <activation>
    <property>
      <name>test</name>
      <value>true</value>
    </property>
  </activation>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8</version>
      <!-- 
        we don't need the test scope since we want the jar plugin to include
        it in classpath 
      -->
      <!-- scope>test</scope --> 
    </dependency>
  </dependencies>
</profile>

:

$>mvn -Dtest=true package
0

jar mvn. , mvn . , mvn, , maven-assembly-plugin zip .

maven (). , . , - " " PROD, . .

196 if (config.isAddClasspath ()) 197 {198 StringBuffer classpath = new StringBuffer (); 199,200
Artifact List = project.getRuntimeClasspathElements ();

I had one more thought: can this be done using the maven groovy plugin?

0
source

Source: https://habr.com/ru/post/1759293/


All Articles