【发布时间】:2021-01-24 15:51:59
【问题描述】:
我使用 Maven 3.6.3 在 IntelliJ 中构建了一个 BDD Serenity 项目。我需要构建一个可运行的 jar 文件,以便 BDD 测试可以在另一台笔记本电脑上运行。
我运行“mvn clean package”并收到消息“JAR 将为空 - 没有内容被标记为包含!”
请帮忙,我不确定如何解决这个问题。下面是输出,以及 POM 文件。
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< equalexperts:hotelbookings >---------------------
[INFO] Building Serenity project with JUnit and WebDriver 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hotelbookings ---
[INFO] Deleting C:\Intelli- Projects\serenity-tutorials\hotelbookings\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hotelbookings ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Intelli- Projects\serenity-tutorials\hotelbookings\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ hotelbookings ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hotelbookings ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Intelli- Projects\serenity-tutorials\hotelbookings\test
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ hotelbookings ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\Intelli- Projects\serenity-tutorials\hotelbookings\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ hotelbookings ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ hotelbookings ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\Intelli- Projects\serenity-tutorials\hotelbookings\target\hotelbookings-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.740 s
[INFO] Finished at: 2021-01-24T17:38:50+02:00
[INFO] ------------------------------------------------------------------------
4.0.0
<groupId>equalexperts</groupId>
<artifactId>hotelbookings</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Serenity project with JUnit and WebDriver</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>2.3.2</serenity.version>
</properties>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>https://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
</dependencies>
<build>
<testResources>
<testResource>
<directory>test</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<finalName>ServiceCreate</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.svt.optimoo.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/Test*.java</include>
<include>**/When*.java</include>
<include>**/*Story.java</include>
</includes>
<argLine>-Xmx512m</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
【问题讨论】:
-
jar 文件通常是通过编译源代码 src/main.java 来构建的。从 src/test/java 捆绑 JAR 并在另一台机器上运行它是一种不好的做法。必须有 CI - Jenkins 才能完成这项工作!