我做“mvn clean package”并创建一个zip文件(基于我的assembly.xml
)和snapshot.jar
,然后创建zip文件并最后创建jar-with-dependencies.jar
我认为因为zip文件是在创建jar-with-dependencies.jar
之前创建的,所以它从未复制到zip文件中。
如何强制maven将snapshot.jar
和jar-with-dependencies.jar
复制到zip文件中(换句话说,如何在调用程序集目标之前构建强制jar-with-dependencies,以便所有的罐子都会被复制到zip文件中)
这是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>
<groupId>com.mycomonay</groupId>
<artifactId>artid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>art</name>
<description>artdescription</description>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId>
<version>2.4</version> <configuration> <archive> <manifestEntries> <Built-By>xyz</Built-By>
<Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration>
</plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestEntries>
<Built-By>abc</Built-By>
<Class-Path>.</Class-Path>
</manifestEntries>
<manifest>
<!-- <addClasspath>true</addClasspath> -->
<mainClass>com.mycomonay.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- <resources> <resource> <directory>src/main/resources</directory> </resource>
</resources> -->
</build>
这是assembly.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<!-- <baseDirectory>/</baseDirectory> -->
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
</fileSet>
<fileSet>
<directory>${project.basedir}/scripts</directory>
<outputDirectory>scripts</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*with-dependencies.jar</include>
</includes>
</fileSet>
答案 0 :(得分:1)
您绝对可以将single
目标分为两次执行(请参阅https://stackoverflow.com/a/8726969/3114959或https://stackoverflow.com/a/15799254/3114959)。
Maven以与有效pom 中出现的顺序相同的顺序执行事物(只要属于同一阶段),所以如果你指定两个执行分开,你应该没事。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-jar-with-dependencies</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
<execution>
<id>make-the-zip</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
因此,您将在构建期间看到2次执行:
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (create-jar-with-dependencies) @ artid ---
[INFO] ... some more output ...
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (make-the-zip) @ artid ---
后一个执行(make-the-zip
)肯定可以包含前者的结果(create-jar-with-dependencies
)。