使用maven-compiler-plugin排除软件包适用于一个软件包,但不适用于另一个软件包 [英] Excluding package with maven-compiler-plugin works for one package but doesn't work for another

查看:336
本文介绍了使用maven-compiler-plugin排除软件包适用于一个软件包,但不适用于另一个软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目具有以下程序包结构:

My project has the following package structure:

src/
  com.my.app.school.course
    -Course.java
    ...

  com.my.app.school.course.free
    -CourseFree.java  

我使用Maven构建项目,在pom.xml中定义了 maven -compiler-plugin 进行测试,以排除包含所有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.

我首先尝试了以下方法来排除包裹com.my.app.school.course.free:

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>

它有效!我的意思是说,运行mvn clean install之后,target/classes/下的最终版本没有软件包com/my/app/school/course/free.

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 .

然后,我尝试排除包com.my.app.school.course.我只是用值<exclude>**/com/my/app/school/course/*</exclude> 替换上面的<exclude>标签.我认为它也应该起作用,但事实并非如此!在target/classes/下,我看到所有软件包,没有软件包被排除在外.为什么?

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?

我要实现的是排除软件包com.my.app.school.course,但保留pacakge com.my.app.school.course.free,如何实现呢?

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?

========更新=======

我觉得可能是因为我尝试排除的软件包包含了其他软件包中已使用的Java类.我会验证我的猜测.

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.

推荐答案

好,我发现了排除无效的原因.

Ok, I found the reason why the exclusion doesn't work.

因为我尝试排除的软件包下的某些Java类已在其他软件包中使用.似乎maven-compiler-plugin很聪明,可以检测到这一点.

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.

这篇关于使用maven-compiler-plugin排除软件包适用于一个软件包,但不适用于另一个软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆