Cannot test through maven using the package-info.java file in the same package as the test class

The strangest thing that ever happened today was when I ran a simple test class through Maven. There is no problem inside the Eclipse IDE, no matter what.

My package has one JUnit test case class and a documentation class package-info.java .

I found that package-info.java somehow interfering with the Maven compiler plugin. Upon removal, the test passes normally.

When package-info.java exists in a package, Maven writes this to the log:

 [ERROR] Failure executing javac, but could not parse the error: javac: invalid source release: **/*.java Usage: javac <options> <source files> use -help for a list of possible options 

How can I make Maven skip package-info.java so that I can save it in the package folder?

+4
source share
1 answer

I had the same problem a few days ago and it was resolved by entering it in the pom.xml file:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> <executions> <execution> <phase>test-compile</phase> <goals> <goal>testCompile</goal> </goals> <configuration> <source>1.6</source> <target>1.6</target> <testSource> **/*.java</testSource> <testExcludes> <exclude>**/package-info.java</exclude> </testExcludes> </configuration> </execution> </executions> </plugin> 

This is the testExcludes element that makes Maven forget the package-info.java class.

+4
source

All Articles