Java – Remove nested test classes with maven2

inner-classesjavamaven-2nested-class

I use nested classes for accessing private members in JUnit tests. They are alaways named "TestProxy".

I would like to remove them at Build time using maven2, to not include it into the jar file.

  • Is there any configuration option?
  • Can it be done with a plugin? If so, a prototype would be nice! 😉

Thanks

Edit: Why use private methods? I need to inject data from 3rd party systems, that just can't be called for every JUnit test run. And i really don't want a public setter for private data, or sooner or later another programmer may misuse it.

Best Answer

Here is the answer: It can be configured with maven. Just insert the following code into the file pom.xml in the build/plugins section:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
 <configuration>
   <excludes>
     <exclude>**/*$TestProxy*</exclude>
   </excludes>
 </configuration>
</plugin>

@see the Documentation: http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#excludes