简体   繁体   中英

Create Maven Assembly that pulls JARS files

I want to create a Maven Assembly that pulls down a few JAR files (Spring boot JARS), so that I can package this up for distribution.

I can get the Maven Assembly plugin to work where the type is WAR, but not for JAR.

eg

<?xml version="1.0" encoding="UTF-8"?>

<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.test</groupId>
  <artifactId>bom-build</artifactId>
  <name-bom-build</name>
  <version>1.0.0-SNAPSHOT</version>


  <dependencies>
    <dependency>
      <groupId>com.test.group</groupId>
      <artifactId>bootapp</artifactId>
      <version>1.0.0</version>
      <type>WAR</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/src.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

src.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>distribution</id>
  <formats>
    <format>zip</format>
    <format>dir</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <includes>
        <include>com.test:*:war:*</include>
        <include>com.test:*:jar:*</include>
      </includes>
      <useProjectArtifact>true</useProjectArtifact>
      <outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
      <outputDirectory>jars</outputDirectory>
      <unpack>false</unpack>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/resources</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

Is there a way to build an assembley to pull together a list of JAR files?

I suggest you add the desired JARs a dependencies in your POM:

  <dependencies>
    ...
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    ...
  </dependencies>

(or however specific you need) and add another dependencySet:

  <dependencySets>
    ...
    <dependencySet>
      <includes>
        <include>org.springframework.*:*:*</include>
      </includes>
      <outputDirectory>jars</outputDirectory>
      <unpack>false</unpack>
    </dependencySet>
  </dependencySets>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM