为什么可以';maven部署插件不能解析我的自定义系统属性吗?

为什么可以';maven部署插件不能解析我的自定义系统属性吗?,maven,groovy,maven-3,gmaven-plugin,maven-deploy-plugin,Maven,Groovy,Maven 3,Gmaven Plugin,Maven Deploy Plugin,我正在使用gmaven插件在我的POM中添加。这似乎是可行的,因为我能够使用maven antrun插件成功地回显属性;然而,maven部署插件似乎完全不知道该属性,并且无法解析它 POM的相关部分: <build> <plugins> <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>

我正在使用gmaven插件在我的POM中添加。这似乎是可行的,因为我能够使用maven antrun插件成功地回显属性;然而,maven部署插件似乎完全不知道该属性,并且无法解析它

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>

为什么maven antrun插件能够解析我的自定义系统属性,而maven deploy插件不能解析?

我不确定,但我相信
${…}
占位符语法只能解析项目属性。我相信系统属性是在构建中的某个点添加到项目属性的,这就是为什么系统属性可以以这种方式使用,但是在构建中稍后添加的系统属性将不可用。你应该这样做。

我不确定这两者之间有什么关系,但我最近发现了一个问题,我使用了
${…}
语法和gmaven插件。在我的插件中,我正在为构建生成最终名称。pom的这一部分看起来像:

<build>
   <finalName>${my.final.name}</finalName>
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 myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar

mvn clean deploy
有效吗?@Raghuram-不,我用这个POM创建的唯一工件是一个.sql文件,而Maven没有sql打包类型。这意味着我不能运行deploy:deploy,而必须运行deploy:deploy文件。谢谢,这是很好的信息。对我来说,有效的方法是使用
project.properties.setProperty('nodotsversion',“${env.PATCH_VERSION}.replace('.','')”)
设置项目属性。然后,我可以在POM中使用
${nodotsversion}
引用该属性。请注意,在它前面加上“project”,例如
${project.nodotsversion}
将不起作用。在配置第二个mojo时,
project.getProperties().get(“myprop”)
null
,即使
gmaven
mojo设置
myprop
已经运行。古怪的
[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]
String myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar