我正在尝试完全自动化构建,最重要的是,在travis-ci中使用maven的版本。我尝试这样做的方式是提供用户名和密码命令行作为属性,并在settings.xml
文件中替换它们。然后,在运行构建时,我将settings.xml
的位置覆盖为我签入的文件。构建和释放所需的所有内容都需要检入到repo中。虽然maven看起来不像是在进行财产替代。
示例:
settings.xml
<?xml version='1.0' encoding='UTF-8'?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${SONATYPE_USERNAME}</username>
<password>${SONATYPE_PASSWORD}</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>${SONATYPE_USERNAME}</username>
<password>${SONATYPE_PASSWORD}</password>
</server>
</servers>
</settings>
构建命令:
mvn --settings $PWD/settings.xml -e -X -B release:prepare release:perform "-DSONATYPE_USERNAME=YYIaF/A4" "-DSONATYPE_PASSWORD=kowLPBgK+/kRiC+O96YZT1ibvxrdcKc" -Dgpg.passphrase=passphrase
这些不是实际的凭据,但我包含了一些事实,他们有一些很重要的时髦字符。
错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project foo-parent: Failed to deploy artifacts: Could not transfer artifact com.baz:foo-parent:pom:3.0.3 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/baz/foo-parent/3.0.3/foo-3.0.3.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
但如果我以官方方式(.m2 / settings.xml)这样做 - 一切都很好。
由于目标是完全自动化travis-ci的发布,如果只是直接的方式来做到这一点,我很满意。