2011-09-29 30 views
1

我在我的POM中使用gmaven-plugin到set a custom system property。这似乎工作,因为我能够使用maven-antrun-plugin成功回显属性;然而,maven-deploy-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-插件能解决我的自定义系统属性,而maven-deploy-plugin不是?

+0

'mvn clean deploy'工作吗? – Raghuram

+0

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

回答

2

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

+0

谢谢,这是很好的信息。什么工作对我来说是设置项目属性与\t \t \t \t \t \t \t \t'project.properties.setProperty( 'nodotsversion', “$ {} env.PATCH_VERSION” 替换( '', ''))' 。然后我可以在POM中用'$ {nodotsversion}'引用该属性。请注意,它前面加上“project”,例如'$ {project.nodotsversion}'不起作用。 –

+0

没有为我工作。还没有弄清楚为什么。 –

+0

当第二个mojo被配置时,即使'gmaven' mojo设置'myprop'已经运行,'project.getProperties()。get(“myprop”)''为'null'。奇。 –

0

我不确定这是如何相关的,但我最近发现了一个我使用${...}语法和gmaven插件的问题。在我的插件中,我正在为构建生成一个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 myvar = "prefix${someothervar}suffix" 
project.properties['my.final.name'] = myvar 
相关问题