I want to configure a manual file deployment to a remote repository using either the snapshot repository (using configured property project.distributionManagement.snapshotRepository.url) if the current version of the project is a snapshot version or to the release repository (using configured property project.distributionManagement.repository.url) otherwise.
I want to deploy a swagger json schema to the repository and I did not find any way other than a manual deployment.
There is a work around using builder helper bsh to use the correct repository from the distribution management configuration. It sets a property with the correct value. Then the maven deploy plugin is called with the goal deploy-file and this URL.
<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>