【问题标题】:Exclude Test Classes in dependend Maven JAR排除依赖 Maven JAR 中的测试类
【发布时间】:2012-05-27 22:17:46
【问题描述】:

我们有一个 EAR 项目,它组装了一个 WAR 文件并有一些 JAR 文件作为依赖项。 EAR 的 POM.xml 如下所示:

<dependencies>
        <dependency>
            <groupId>our.package</groupId>
            <artifactId>package-impl</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
            <scope>runtime</scope>
        </dependency>   
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>${maven.ear.plugin.version}</version>
                <configuration>
                    <version>5</version>
                    <generateApplicationXml>false</generateApplicationXml>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                        <webModule>
                            <groupId>de.project</groupId>
                            <artifactId>project.war</artifactId>
                            <bundleDir>/</bundleDir>
                            <bundleFileName>project.war</bundleFileName>
                            <contextRoot>project</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>

在 EAR 中作为 JAR 包含的 package-impl 中包含一些测试类。不幸的是,当 EAR 被组装时,这些测试类与 JAR 捆绑在一起。除了方面,Maven 应该包含测试类,当组装 EAR 时,如何在 JAR 中排除这些测试类?

package-impl 中的所有测试类都在 src/test/java 源文件夹中。

问候 斯文

更新: 当我从 EAR 手动构建独立的 package-impl 时,不包括测试类(如预期的那样)。

更新2

这里是完整的 package-impl POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>project-impl</artifactId>
    <parent>
        <groupId>de.company</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../project</relativePath>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>${jee6.version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>${hibernate.jpa-api.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-vfs</artifactId>
            <version>${jboss-vfs.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>${commons-lang.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>${dom4j.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsf-api.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- depenencies on third party modules -->
        <dependency>
            <groupId>org.jboss.solder</groupId>
            <artifactId>solder-impl</artifactId>
            <version>${jboss.solder.solder-impl.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.seam.persistence</groupId>
            <artifactId>seam-persistence</artifactId>
            <version>${org.jboss.seam-persistence.version}</version>
            <exclusions>
                <!-- already provided by jboss as -->
                <exclusion>
                    <groupId>org.jboss.spec.javax.servlet</groupId>
                    <artifactId>jboss-servlet-api_3.0_spec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.richfaces.core</groupId>
            <artifactId>richfaces-core-impl</artifactId>
            <version>${jboss.richfaces.version}</version>
        </dependency>
        <dependency>
            <groupId>org.richfaces.ui</groupId>
            <artifactId>richfaces-components-ui</artifactId>
            <version>${jboss.richfaces.version}</version>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>${org.reflections.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.0.0.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>1.0.0.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
            <version>1.0.0.CR3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>1.1.5.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>       
    </dependencies>
</project>

UPDATE3

这最终成为一个日食设置。 EAR-Project 有一个包含测试文件夹的文件夹列表。

【问题讨论】:

  • jar 里面有测试类是什么意思?它不应该。里面应该只有编译的主类。这 package-impl 工件也是由 Maven 构建的吗?
  • 如果您在 EAR/JAR 中有测试类而不是使用默认值。您的配置中有一些奇怪的东西。通常在 jar 中不会打包任何测试类。
  • @Michal Kalinowski package-impl 具有 TestCases,它们(出于某种原因)被编译为 java 类并打包到 package-impl JAR 中,该 JAR 依赖于 EAR 项目。是的,package-impl 也是使用 Maven 构建的。
  • 好的,给我们package-impl模块的POM。我 99% 确信它有某种奇怪和 hacky POM,其中包括以某种方式将测试类包含到主要工件中。通常,如果您需要部署已编译的测试类并使用标准方式执行此操作,则有一个单独的 test-jar 类型的工件。

标签: java maven jar ear


【解决方案1】:

问题必须出在依赖 JAR 文件的模块中。也许有人已经将构建配置为在 JAR 中包含测试类。如果是这样,您应该修复模块(即它的 POM 文件)以不这样做,而不是尝试在您的 EAR 模块中处理它。

【讨论】:

  • package-impl的POM.xml中没有特殊配置。但是,我确实尝试了编译器和 jar-plugin 以排除所有测试类,但它不起作用。
  • 不过,问题出在那个区域。以“正常方式”构建的“正常”Maven 构建 JAR 文件不包含测试类。您是否尝试过自己构建依赖 JAR?
  • 是的,我独立于 EAR 构建 JAR,并且不包括编译的测试类。正如预期的那样。
【解决方案2】:

过去我不小心将测试类放在 src/main/java 而不是 src/test/java 中,这在 eclipse 中有效(编译、运行)但我的构建失败了,因为 JUnit 不在类路径中建造。 在您的情况下可能正确,也可能不正确,但值得检查。

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 2019-11-25
    • 2015-09-23
    相关资源
    最近更新 更多