如何包括Maven的遮阳插件创建于罐测试类? [英] How to include test classes in Jar created by maven-shade-plugin?

查看:137
本文介绍了如何包括Maven的遮阳插件创建于罐测试类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我打包测试类中使用Maven依赖一个可执行的JAR,但我在努力得到这个权利。

I'm trying to package my test classes in to an executable jar with dependencies using Maven, but I'm struggling to get this right.

这是我的pom.xml至今:

This is my pom.xml so far:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.c0deattack</groupId>
    <artifactId>executable-tests</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>executable-tests</name>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.21.0</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>cucumber-tests</finalName>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>cucumber.cli.Main</mainClass>
                                </transformer>
                            </transformers>
                            <artifactSet>
                                <includes>
                                    <include>info.cukes:*</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.c0deattack</groupId>
                        <artifactId>executable-tests</artifactId>
                        <version>1.0</version>
                        <type>test-jar</type>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

当我执行 MVN清洁套装构建创建3罐:

When I execute mvn clean package the build creates 3 jars:


  • 执行检验-1.0.jar //由MVN包相建

  • 执行检验-1.0-teststjar //由JAR-插件内置

  • 黄瓜tests.jar //用遮阳插件打造

黄瓜tests.jar 包含 info.cuke 相关性,但它不包含可执行的测试-1.0-tests.jar

Cucumber-tests.jar contains the info.cuke dependencies but it doesn't contain the executable-tests-1.0-tests.jar.

我已经做了所有的事情,试图包括测试类,但没有奏效,我错过什么?

I've done all sorts of things to try and have the test classes included but nothing has worked, what am I missing?

编辑:我已经把我的例子项目,GitHub上,如果任何一个幻想与玩了:)的 https://github.com/C0deAttack/ExecutableTests

I've pushed my example project to GitHub if any one fancies playing around with it :) https://github.com/C0deAttack/ExecutableTests

推荐答案

我已经解决了我的问题的不同方式;使用其他两个插件。

I've solved my problem a different way; using two other plugins.

首先,我使用 Maven的依赖关系的插件来得到的依赖关系,并在本地解压它们,然后我用的maven-JAR-插件来创建一个测试-JAR ,包括从解包依赖的类。

First I use the maven-dependency-plugin to get the dependencies and unpack them locally, then I use the maven-jar-plugin to create a test-jar and include the classes from the unpacked dependencies.

这篇关于如何包括Maven的遮阳插件创建于罐测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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