如何运行两次构建,以便可以使用不同的依赖项获得两个工件? [英] How to run build twice so that I can get two artifacts using different dependencies?

查看:75
本文介绍了如何运行两次构建,以便可以使用不同的依赖项获得两个工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,我们想构建两个单独的jar,一个包含32位库,另一个包含64位库.

I've got a Maven project and we want to build two separate jars, one containing 32-bit libraries and one containing 64-bit libraries.

我们当前的构建将生成32或64位工件,具体取决于运行该构建的操作系统.

Our current build will produce either 32 or 64-bit artifacts depending on the operating system on which the build is run.

关于我们当前设置的概述:

An overview of how we're currently set up:

    <properties>
            <env.arch>${sun.arch.data.model}</env.arch>
    </properties>

    <build>
    <pluginManagement>

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                    <id>copy-native</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                    <artifactItems>
                    <artifactItem>
                        <groupId>artifact-for-${env.arch}</groupId>
                        <artifactId>artifact.name</artifactId>
                    </artifactItem>
                        ...

                   <plugin>
                       <artifactId>maven-jar-plugin</artifactId>
                       <executions>
                           <execution>
                               <phase>package</phase>
                           </execution>
                       </executions>

所以它正在做的是复制与${env.arch}属性值匹配的依赖项,然后使用maven-jar-plugin构建jar.

So what it's doing is copying the dependencies that match the value of our property for ${env.arch}, then building the jar using the maven-jar-plugin.

我们需要做的是从一个构建中生成2个jar,一个包含32位依赖项,另一个包含64位依赖项.

What we need to be able to do is produce 2 jars from one build... one containing the 32 bit dependencies and one containing the 64 bit dependencies.

任何人都可以为我们如何完成此工作提供任何指导吗?

Can anyone offer any guidance to how we can get this done?

谢谢

推荐答案

这可以通过在配置文件中指定依赖项来完成,例如 this答案.尽管要创建两个工件,您都必须构建项目两次.您可能还应该为每个配置文件配置 jar插件为工件分配不同的分类器.

This can be done by specifying the dependencies in profiles like in this answer. You would have to build your project two times though to create both artifacts. You should probably also configure the jar plugin per profile to give different classifiers to the artifacts.

您也可以只在配置文件中设置一个属性,然后在依赖项部分中使用该属性,而不是环境变量.

You could also just set a property in the profiles ant use this later in the dependency section instead of the environment variable.

您还可以根据当前系统的体系结构激活配置文件,以使默认情况有效:

You can also activate the profiles based on the architecture of the current system, to have a working default case:

<profile>
    <activation>
        <os>
            <arch>x86</arch>
        </os>
    </activation>
    ...
</profile>

所有激活选项均在此页面中进行了描述.

All activation options are described on this page.

这篇关于如何运行两次构建,以便可以使用不同的依赖项获得两个工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆