问题
My project has the following package structure:
src/
com.my.app.school.course
-Course.java
...
com.my.app.school.course.free
-CourseFree.java
I use Maven to build the project, in my pom.xml, I defined maven-compiler-plugin to test excluding a package with all its java classes.
I first tried following way to exclude package com.my.app.school.course.free
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
<exclude>**/com/my/app/school/course/free/*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
It works! I mean after run mvn clean install
, the final build under target/classes/ doesn't have the package com/my/app/school/course/free
.
Then, I tried to exclude package com.my.app.school.course
. I simply replace the above <exclude>
tag with value <exclude>**/com/my/app/school/course/*</exclude>
. I thought it should work too , but it doesnt! Under target/classes/ I see all packages, no package is excluded. Why?
What I want to achieve is to exclude package com.my.app.school.course
but keep pacakge com.my.app.school.course.free
, how to achieve this?
======== update ========
I feel it might be because the package I tried to exclude contain java classes that have been used in other packages. I will verify my guess.
回答1:
Ok, I found the reason why the exclusion doesn't work.
Because some java classes under the package which I tried to exclude have been used in other packages. Seems maven-compiler-plugin is smart to detect that.
来源:https://stackoverflow.com/questions/25323258/excluding-package-with-maven-compiler-plugin-works-for-one-package-but-doesnt-w