3

I have a project called "commons" that contains common includes for both runtime and test.

In the main project I added a dependency for commons:

    <dependency>
        <groupId>com.alexb</groupId>
        <artifactId>commons</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

However the test common files are not included. So I added :

    <dependency>
        <groupId>com.alexb</groupId>
        <artifactId>commons</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>test-jar</type>       
    </dependency>

However when type is test-jar, the runtime is not included.

Unfortunatelly, it seems I cannot include both:

<type>jar,test-jar</type>       

What can I do to include both?

user1883212
  • 7,539
  • 11
  • 46
  • 82
  • 1
    Why dont you copy dependency twice and making one of them's type jar and the other one is test-jar ??? – Sercan Ozdemir Dec 18 '15 at 15:30
  • I didn't created two projects because the includes for testing are just one file and it sounded no-sense to have a separate project for just one java file – user1883212 Dec 18 '15 at 15:33
  • As far as I know making it jar only should make it available on test scope already, doesnt it ? – Sercan Ozdemir Dec 18 '15 at 15:36
  • If I use jar alone, the testing files are not included. I tried again now and I confirm. – user1883212 Dec 18 '15 at 15:39
  • I thought to put this test include file into the runtime path and then include it into my tests. The only problem is that this file contains a main method and this causes some issues. – user1883212 Dec 18 '15 at 15:41
  • 1
    This shows you should separate out your test-jar part project into a separate project which you then can use independent of the others. – khmarbaise Dec 18 '15 at 15:42

1 Answers1

0

As @khmarbaise mentioned in the comments you should separate your test-jar part project.

I presume you have in the commons pom.xml something like this which generates common test-jar.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
      <execution>
        <goals>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

The problem with this approach is that you don't get the transitive test-scoped dependencies automatically.

Check this link for more details:

https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

Rob
  • 708
  • 8
  • 27