我希望使用快照存储库(如果项目的当前版本是快照版本,则使用已配置的属性project.distributionManagement.snapshotRepository.url) )将手动文件部署配置到远程存储库,或者配置到发布存储库(否则使用配置的属性project.distributionManagement.repository.url) )。
我想要将一个swagger模式部署到存储库中,除了手动部署之外,我没有找到任何其他方法。
发布于 2016-12-16 09:29:11
在使用builder使用来自分发管理配置的正确存储库方面有一项工作。它设置一个具有正确值的属性。然后,使用目标部署文件和这个URL调用maven部署插件。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<goals>
<goal>bsh-property</goal>
</goals>
<configuration>
<properties>
<property>deploy.url</property>
</properties>
<source>deploy.url = project.getVersion().endsWith("-SNAPSHOT") ? project.getDistributionManagement().getSnapshotRepository().getUrl() : project.getDistributionManagement().getRepository().getUrl() ;</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>${deploy.url}</url>
<repositoryId>releases</repositoryId>
<file>${swagger.directory}/swagger.json</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>json</packaging>
<classifier>swagger</classifier>
</configuration>
</execution>
</executions>
</plugin>发布于 2016-12-16 10:00:00
如果您需要部署没有相应pom.xml文件支持的工件(可能是json文本文件),则可以使用deploy目标:
http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
这允许您将来自任何来源的任何类型的工件部署到maven存储库中,通过命令行指定组、工件和版本坐标以及所需的任何其他内容。
为了根据您的版本将其部署到正确的位置,我可以建议您使用我们为类似目的构建的ant脚本片段:
<condition property="url" value="${snapshots.repo.url}" else="${releases.repo.url}">
<contains string="${project.version}" substring="-SNAPSHOT"/>
</condition>
<exec executable="cmd">
<arg value="/c"/>
<arg value="mvn.bat"/>
<arg value="deploy:deploy-file"/>
<arg value="-DgroupId=com.myorg.swagger"/>
<arg value="-DartifactId=swagger_file"/>
<arg value="-Dversion=${project.version}"/>
<arg value="-U"/>
<arg value="-Dfile=./mydir/my_swagger_file.json"/>
<arg value="-Durl=${url}"/>
<arg value="-DrepositoryId=my_repo_id"/>
</exec>这将只在Windows中工作,但很容易适应任何其他操作系统。这里有趣的地方是repositoryId,它应该指向您的settings.xml中的现有身份验证:
...
<servers>
<server>
<id>my_repo_id</id>
<username>your_user_for_deployment</username>
<password>your_pwd_for_deployment</password>
</server>
</servers>
...希望这能帮到你^^
发布于 2020-10-14 20:17:26
@Nicolas的答案是正确的,但deploy阶段在build-helper-maven-plugin中是不正确的。新的属性在生命周期的下一阶段是可见的,所以在本例中它是不可见的。在移除它之后( defeault是有效的),一切都开始工作了。
https://stackoverflow.com/questions/41181118
复制相似问题