代码之家  ›  专栏  ›  技术社区  ›  KLE rslite

Maven程序集包含问题

  •  4
  • KLE rslite  · 技术社区  · 16 年前

    ,使用汇编插件。

    我们有一个使用Ant的历史程序集,需要许多改进。在第一阶段,我试图使用干净的Maven程序集获得相同的结果。稍后,我将对其进行改进。

    在我的程序集中,我希望在几个版本中都有相同的jar工件。我想要:

        commons-beanutils-1.7.0.jar
        commons-beanutils-1.8.0.jar
    

    这是我用于组装项目的pom.xml。如果我只指定一个或另一个,一切都会奏效,除非我明显没有得到另一个。

          <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.7.0</version>
          </dependency>
          <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.0</version>
          </dependency>
    
    1 回复  |  直到 6 年前
        1
  •  4
  •   Rich Seller    16 年前

    Maven不希望您这样做,因为运行时的行为是不确定的。

    如果你确实有充分的理由这样做,为了避免这个问题,你需要将依赖关系指定为 artifactItems 在依赖插件中。以下配置将把jar的两个版本复制到target/output,如果依赖插件在程序集插件之前执行,则可以通过指定 fileSet 指向目标/输出目录:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>commons-beanutils</groupId>
                  <artifactId>commons-beanutils</artifactId>
                  <version>1.7.0</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                </artifactItem>
                <artifactItem>
                  <groupId>commons-beanutils</groupId>
                  <artifactId>commons-beanutils</artifactId>
                  <version>1.8.0</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${project.build.directory}/output</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
          </execution>
        </executions>
      </plugin>
    
    推荐文章