【问题标题】:Why can't the maven-deploy-plugin resolve my custom system property?为什么 maven-deploy-plugin 无法解析我的自定义系统属性?
【发布时间】:2014-04-17 06:02:24
【问题描述】:

我在我的 POM 中使用 gmaven-plugin 到 set a custom system property。这似乎可行,因为我能够使用 maven-antrun-plugin 成功地回显该属性;但是,maven-deploy-plugin 似乎完全不知道该属性并且无法解决它。

POM 的相关部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            System.setProperty("nodotsversion", "${env.PATCH_VERSION}".replace('.', ''))
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version><!-- 1.2 in central -->
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                            <echo message="${nodotsversion}" />     
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.6</version>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <repositoryId>artifactory</repositoryId>
                <packaging>sql</packaging>
                <generatePom>true</generatePom>
                <url>${project.distributionManagement.snapshotRepository.url}</url>
                <groupId>com.company.product</groupId>
                <artifactId>patch${nodotsversion}</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <file>${WORKSPACE}/myfile.sql</file>
            </configuration>
        </plugin>
    </plugins>
</build>

当我使用mvn clean install deploy:deploy-file 运行此程序时,我收到以下错误:

Caused by: org.apache.maven.plugin.MojoExecutionException: The artifact information is incomplete or not valid:
  [0]  'artifactId' with value 'patch${nodotsversion}' does not match a valid id pattern.

为什么 maven-antrun-plugin 能够解析我的自定义系统属性,而 maven-deploy-plugin 却不行?

【问题讨论】:

  • mvn clean deploy 工作吗?
  • @Raghuram - 不,我用这个 POM 创建的唯一工件是 .sql 文件,Maven 没有 sql 打包类型。这意味着我无法运行 deploy:deploy 而必须运行 deploy:deploy-file。

标签: maven groovy maven-3 gmaven-plugin maven-deploy-plugin


【解决方案1】:

我不确定,但我相信${...} 占位符语法只能解析项目属性。我相信系统属性会在构建中的某个点添加到项目属性中,这就是系统属性以这种方式可用的原因,但稍后在构建中添加的系统属性将不可用。您应该改为add the property to the project properties

【讨论】:

  • 谢谢,这是很好的信息。对我有用的是使用project.properties.setProperty('nodotsversion',"${env.PATCH_VERSION}".replace('.', '')) 设置项目属性。然后我可以在我的 POM 中使用${nodotsversion} 引用该属性。请注意,以“项目”为前缀,例如${project.nodotsversion} 将不起作用。
  • 配置第二个 mojo 时,project.getProperties().get("myprop")null,即使 gmaven mojo 设置 myprop 已经运行。奇数。
【解决方案2】:

我不确定这有什么关系,但我最近发现了我在使用 ${...} 语法和 gmaven-plugin 时遇到的问题。在我的插件中,我正在为构建生成一个 finalName。这部分 pom 看起来像:

<build>
   <finalName>${my.final.name}</finalName>

然后,在 maven &lt;source&gt; 部分我有类似的东西:

def myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar

pom 是为了战争。当我运行 maven 时,输出总是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project myservice: The parameters 'warName' for goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war are missing or invalid -> [Help 1]

经过一番摸索,我终于想出了解决问题的方法。 myvar 需要声明为 String

String myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2020-07-16
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多