java 使用 maven-compiler-plugin 排除包适用于一个包但不适用于另一个包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25323258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:50:35  来源:igfitidea点击:

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

javamavenmaven-3maven-compiler-plugin

提问by Leem.fin

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-pluginto test excluding a package with all its java classes.

我使用 Maven 来构建项目,在我的 pom.xml 中,我定义了maven-compiler-plugin来测试排除一个包及其所有 java 类。

I first tried following way to excludepackage com.my.app.school.course.free:

我首先尝试以下方法来排除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.

有用!我的意思是在 run 之后mvn clean install, target/classes/ 下的最终构建没有 package com/my/app/school/course/free

Then, I tried to exclude package com.my.app.school.course. I simply replacethe 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?

然后,我尝试排除 package com.my.app.school.course。我只是用 value替换了上面的<exclude>标签<exclude>**/com/my/app/school/course/*</exclude>。我认为它也应该工作,但它没有!在 target/classes/ 我看到所有包,没有包被排除在外。为什么?

What I want to achieve is to exclude package com.my.app.school.coursebut keep pacakge com.my.app.school.course.free, how to achieve this?

我想要实现的是排除 packagecom.my.app.school.course但保留 pacakge com.my.app.school.course.free,如何实现?

======== 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.

我觉得可能是因为我试图排除的包包含在其他包中使用过的 java 类。我会验证我的猜测。

回答by Leem.fin

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.

因为我试图排除的包下的一些java类已经在其他包中使用了。似乎 maven-compiler-plugin 很聪明地检测到这一点。