简体   繁体   中英

Is the content of the Maven Assesmnly plugin's jar-with-dependencies descriptorRef documented as an example assembly descriptor file anywhere?

The following see How can I create an executable jar with dependencies using Maven? shows how to create an executable jar with the Maven plugin.

  <build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

However I wish to exclude some of the dependencies which are in my POM. All I want to do is to add

   <dependencySets>
    <dependencySet>
        <useStrictFiltering>true</useStrictFiltering>
        <scope>compile</scope>
        <excludes>
            <exclude>com.excluded:artifact</exclude>
        </excludes>
    </dependencySet>
</dependencySets>

to the above but I cannot , because I need to add that in a separate assembly descriptor. What I want to do is exactly the same as jar-with-dependencies but with the exclusion. Is there somewhere where an equivalent assembly descriptor file is described so I can edit it? Is there any way to 'inherit' jar-with-dependencies and add my exclusions?

See The Maven Documentation on pre defined descriptors for the equivalent of jar-with-depedencies.

So I can change the POM I am using to build 'super jar' as follows;

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.Main</mainClass>
                    </manifest>
                </archive>
                <descriptors>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <!-- Uncomment this for automatic creation of the Complete jar
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
             -->
        </plugin>

And in the directory src/main/assembly/assembly.xml I can put the following which is essentially the same as the jar-with-dependencies descriptor with my exclusions;

<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">
      <!-- TODO: a jarjar format would be better -->
      <id>jar-with-dependencies</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>true</useProjectArtifact>
          <unpack>true</unpack>
          <scope>runtime</scope>
            <excludes>
                <exclude>com.local.depedency:artifact_id</exclude>
                <exclude>transitive.depedency.so.way.down:artifact_id</exclude>
            </excludes>
        </dependencySet>
      </dependencySets>
</assembly>

I think that you can use scope "compile" :

<dependency>
    <groupId>com.xxxx</groupId>
    <artifactId>xxxxxx</artifactId>
    <version>3.x</version>
    <scope>compile</scope>
</dependency>

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