为什么 maven-部署-插件无法解析我的自定义系统属性?



我使用gwen -plugin在我的POM中设置自定义系统属性。这似乎是有效的,因为我能够成功地回声属性使用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不能?

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

我不确定这是如何相关的,但我最近发现了一个问题,我正在使用${...}语法和gwen -plugin。在我的插件中,我正在为构建生成一个finalName。这部分内容如下:

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

然后,在maven <source>部分中,我有如下内容:

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

这首诗是为了一场战争。当我运行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

最新更新