Richard
Richard

Reputation: 239

How to modify pom file to add src/test/java files to maven jar with dependancies

I need to include src/test/java files to my jar with dependancies. But when I create the jar it fails because it cannot find the classes. Here is the pom section. Any help would be appreciated. And i compile with: mvn clean assembly:single

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
   </configuration>
   <executions>
     <execution>
       <phase>package</phase>
       <goals>
         <goal>single</goal>
       </goals>
     </execution>
   </executions>
</plugin>

Upvotes: 1

Views: 2165

Answers (3)

Richard
Richard

Reputation: 239

Wanted to share how I got it to work, although very ugly. To reiterate I wanted to add the test-classes to the class path only when I made my jar with dependancies. What I did:

switched from assembly-pludin to shade-plugin And moved the .class files i needed from target/test-classes to proper place in the jar

<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
    <file>target/test-classes/path/to/class/i/need/file.class</file>
    <resource>in/classpath/destination/of/class/i/need/file.class</resource>
</transformer>

its glorified copy paste and did not see a way to do so via directory so did it 1 .class at a time.

Very ugly, not dynamic, and I am still looking for a better way. But for now it will do.

Upvotes: 0

WeMakeSoftware
WeMakeSoftware

Reputation: 9162

Or you can use maven resource plugin and mark the src/test/java as additional source

similar question is asked here

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240996

by default it is not included, you can have greater amount of flexibility with maven assembly plugin you can use that to generate jar with whatever content you want to put in

Upvotes: 0

Related Questions