【问题标题】:Maven assembly include snapshot depedenciesMaven 程序集包括快照依赖项
【发布时间】:2014-06-05 19:35:40
【问题描述】:

我注意到 maven-assembly-plugin 不想在程序集 jar 中包含快照依赖项。这是设计使然还是我做错了什么。

       <dependency>
        <groupId>com.xxx.zzz</groupId>
        <artifactId>projectname</artifactId>
        <version>1.7.0-SNAPSHOT</version>
      </dependency>

有多个像这样的快照依赖项,所以我讨厌在程序集描述符中明确地包含它们。

问题 1: 有没有办法在包中也包含快照依赖项?

问题 2: 您能否帮助弄清楚如何在组装的 jar 中包含所有依赖项(编译、测试、提供和运行时)。默认情况下,maven 只考虑运行时 jars

以下是 pom 中的 maven-assembly 部分

<plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptors>
                            <descriptor>${project.basedir}/assembly.xml</descriptor>
                        </descriptors>
                        <tarLongFileMode>gnu</tarLongFileMode>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

这里是程序集描述符文件

<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>dist</id>
  <includeBaseDirectory>true</includeBaseDirectory>
  <formats>
  <format>jar</format>
 </formats>
 <dependencySets>
 <dependencySet>
    <outputDirectory>lib</outputDirectory>
    <useProjectArtifact>false</useProjectArtifact>
    <useTransitiveDependencies>true</useTransitiveDependencies>
    <unpack>false</unpack>
    <fileMode>0755</fileMode>
    <directoryMode>0755</directoryMode>
    <includes></includes>
 </dependencySet>
 </dependencySets>
<fileSets>
<fileSet>
    <includes>
    <include>database/**</include>
    <include>deploy/**</include>
  </includes>
       <excludes>
            <exclude>**/*.tmp</exclude
      </excludes>
  <directory>${project.basedir}</directory>
 </fileSet>
 </fileSets>
</assembly>

你能解释一下吗?

【问题讨论】:

    标签: java maven maven-assembly-plugin


    【解决方案1】:

    对于问题 1,要包含来自当前构建的快照依赖项,请使用 moduleSet

    http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html

    也就是说,如果它们来自当前反应堆。否则您将不得不构建它们并依赖于发布版本。

    【讨论】:

      【解决方案2】:

      想出了第二个问题的答案。感谢博妮发博:http://bosbluebluesky.blogspot.com/2012/11/maven-package-jar-file-include-all.html

      我所要做的就是在多个依赖集部分分别包含不同的范围

       <dependencySets>
      <dependencySet>
          <outputDirectory>lib</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <unpack>false</unpack>
          <scope>runtime</scope>
          <fileMode>0755</fileMode>
          <directoryMode>0755</directoryMode>
          <includes></includes>
      </dependencySet>
      <dependencySet>
          <outputDirectory>lib</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <unpack>false</unpack>
          <scope>compile</scope>
          <fileMode>0755</fileMode>
          <directoryMode>0755</directoryMode>
          <includes></includes>
      </dependencySet>
      <dependencySet>
          <outputDirectory>lib</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <unpack>false</unpack>
          <scope>provided</scope>
          <fileMode>0755</fileMode>
          <directoryMode>0755</directoryMode>
          <includes></includes>
       </dependencySet>
        <dependencySet>
          <outputDirectory>lib</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <unpack>false</unpack>
          <scope>test</scope>
          <fileMode>0755</fileMode>
          <directoryMode>0755</directoryMode>
          <includes></includes>
        </dependencySet>
       </dependencySets>
      

      【讨论】:

        猜你喜欢
        • 2021-02-16
        • 2023-03-24
        • 1970-01-01
        • 2014-11-04
        • 1970-01-01
        • 2015-04-28
        • 1970-01-01
        • 1970-01-01
        • 2010-11-05
        相关资源
        最近更新 更多