2

I have Maven configured to create test JARs for all builds (snapshot and release) like so:

        <plugin>
            <!-- generate test-jar artifacts for creating test-test dependencies 
                across modules -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

That works but there is an odd behavior which I'd like to fix: Maven now tries to create a test JAR for modules with packaging pom (i.e. the parent POM). It's just a small nuisance but is there an easy way to fix this?

It doesn't create a main JARs for these modules. Maybe it's a bug in the test-jar goal?

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I assume you have that plugin definition in your parent? – khmarbaise Jun 29 '17 at 11:29
  • Can you please Show the complete pom? – Jens Jun 29 '17 at 11:30
  • 2
    there is a flag "skipIfEmpty": https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html#skipIfEmpty - that may help to avoid creating empty jar files – wemu Jun 29 '17 at 11:41
  • @khmarbaise: Yes, it's in the parent POM – Aaron Digulla Jun 30 '17 at 15:37
  • @Jens No. If you want to test it, just add a group/artifact/version header with `pom` – Aaron Digulla Jun 30 '17 at 15:38
  • If you define this definition in the parent it will be inherited to all childs which usually is not the intention. I would suggest to use that configuration only at modules which really need this. This means in modules which expose java code which is used for tests only for others...This should be an exception and not the default... – khmarbaise Jul 01 '17 at 13:01
  • @khmarbaise That doesn't make sense. I need this in most of my modules. The parent and root POM are the only exceptions. – Aaron Digulla Jul 03 '17 at 08:30
  • That sounds wrong to me that each module needs to make a jar of the tests..that would mean that each of the test-jar is used by other modules? – khmarbaise Jul 03 '17 at 17:25
  • Maven will upload my test JARs (byte code) to the company repo (which also doesn't really make sense), but when it does, I want the sources for all my byte code. – Aaron Digulla Sep 04 '17 at 12:18

1 Answers1

3

skipIfEmpty does the trick, kudos to wemu:

        <plugin>
            <!-- generate test-jar artifacts for creating test-test dependencies 
                across modules -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>

                    <configuration>
                        <skipIfEmpty>true</skipIfEmpty>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Documentation: https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html#skipIfEmpty

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820