【问题标题】:injecting new argument/property value to maven profile in module向模块中的 Maven 配置文件注入新的参数/属性值
【发布时间】:2020-07-21 06:06:21
【问题描述】:

我有主 pom.xml 我喜欢从我正在使用的主 mvn 命令行 cli 更改并更改:

<argument>${docker.image}</argument>

参数仅在子模块中: module_y 配置文件不是 module_x

这是我现在正在执行的命令:

mvn clean install -Ddocker_build=build

<artifactId>foo</artifactId>
<version>b1</version>
<packaging>pom</packaging>

 
 <properties>
        <docker.image>www.repo.org:8000/${project.artifactId}:${project.version}</docker.image>      
 </properties>
 
 <modules>
        <module>module_x</module>
        <module>module_y</module>       
 </modules>

这是 module_x 和 module_y 中的部分

<profiles>
        <profile>
       
            <activation>
                <property>
                    <name>docker_build</name>
                    <value>build</value>
                </property>
                <file>
                    <exists>Dockerfile</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>           
                                <phase>install</phase>
                                <configuration>
                                    <executable>docker</executable>
                                    <arguments>
                                        <argument>build</argument>
                                        <argument>-f</argument>
                                        <argument>${project.basedir}/Dockerfile</argument>
                                        <argument>-t</argument>
                                        <argument>${docker.image}</argument>
                                        <argument>.</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
</profiles>

简而言之,我如何从主 mvn 运行中仅更改 module_y 中配置文件 docker_build 中的属性值 ${docker.image}?

【问题讨论】:

  • 您需要为此更改 POM。这是个问题吗?
  • 是的,我不能全部

标签: maven


【解决方案1】:

如果您无法更改 POM,则无法执行此操作。

唯一可能的方法是单独构建模块(使用-pl module_x -am 或类似的东西)并在两种情况下使用不同的命令行参数。

【讨论】:

    猜你喜欢
    • 2016-03-21
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    相关资源
    最近更新 更多