Excluding package with maven-compiler-plugin works for one package but doesn't work for another

本小妞迷上赌 提交于 2020-01-03 11:34:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!