[英]Passing arguments to Maven release build
我正在嘗試使用Maven發布一個庫並執行一個站點部署到sourceforge(我先創建了一個交互式shell)。 該版本由Jenkins工作完成(使用Jenkins的Maven Release Plugin)。
我試過了:
-X -e -Dresume=false -Dusername=puce release:prepare release:perform -Darguments="-Dusername=puce"
和
-X -e -Dresume=false -Dusername=puce -Darguments=-Dusername=puce release:prepare release:perform
但兩次工作都掛在現場:部署第一個模塊:
[INFO] --- maven-site-plugin:3.2:deploy (default-deploy) @ myproject-parent ---
[INFO] Parent project loaded from repository: myGroupId:myOtherproject-parent:pom:1.0
[INFO] Parent project loaded from repository: myGroupId:myOtherproject-parent:pom:1.0
Using private key: /opt/jenkins/.ssh/id_dsa
當我停止工作時,最后會打印以下內容:
Password for ${username}@shell.sourceforge.net: channel stopped
這可能意味着$ {username}未得到解決。
如何解析$ {username}?
編輯:
請注意,以下運行正常:
site-deploy -Psonatype-oss-release -Dusername=puce
編輯2:作為發布的一部分:執行maven執行以下命令:
/usr/share/maven/bin/mvn -s /tmp/release-settings7797889802430474959.xml deploy site-deploy --no-plugin-updates --batch-mode -Psonatype-oss-release -P nexus -f pom.xml
-Dusername=puce
似乎沒有傳遞給這個maven命令......
另請注意help:effective-pom顯示以下maven-release-plugin配置:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release</arguments>
</configuration>
</plugin>
所以'arguments'被定義了,它的值似乎達到了嵌入式maven命令而不是命令行傳遞的值...
我過去成功完成的工作如下:
在POM文件中定義屬性,例如:
<properties> <release.arguments></release.arguments> </properties>
將POM屬性添加到POM文件中的插件配置,例如;
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <configuration> <arguments>${release.arguments}</arguments> ...
通過命令行上的屬性傳遞參數,例如:
mvn release:prepare -Drelease.arguments="-N -Prelease"
希望這可以幫助。
重寫
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release</arguments>
</configuration>
</plugin>
同
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release -Dusername=${username}</arguments>
</configuration>
</plugin>
在其中一個父母做了伎倆。
似乎是一個錯誤,命令行上的值不會覆蓋POM中的值。
我的解決方案類似於Sander Verhagen's
解決方案。 我只添加了一行。
我如何運行:
mvn --batch-mode release:prepare -Denvironment=production
我的配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tag>${artifactId}-${version}-${environment}</tag>
<arguments>-Denvironment=${environment}</arguments>
<releaseProfiles>release</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
不同的是,現在我的子模塊使用變量environment
,我不需要定義它兩次(即-Darguments=-Denvironment=production -Denvironment=production
)。 我還給了我不添加屬性標簽的靈活性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.