Daniel Walton
Daniel Walton

Reputation: 228

maven-deploy-plugin repository

I want to deploy a file using the maven-deploy-plugin. Currently i have the following in my pom:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>deploy-features-xml</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <repositoryId>${project.distributionManagement.snapshotRepository.id}</repositoryId>
                            <url>${project.distributionManagement.snapshotRepository.url}</url>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <file>features.xml</file>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I want to change between the snapshot and release repository based on the version. If the project version is 1-SNAPSHOT the file should be deployed to the snapshot repository, if the project is version 1.0 the file should be deployed to the release repository. But the maven-deploy-plugin hard codes it?

Upvotes: 1

Views: 14257

Answers (2)

Daniel Walton
Daniel Walton

Reputation: 228

The solution that I ended up with was to use the build-helper-maven-plugin and the maven-resources-plugin. This setup means that along with the jar and pom and project will deploy an xml file that can be references in the maven repo as project/xml/features.

Relevant pom plugins:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target/features/features.xml</file>
                                    <type>xml</type>
                                    <classifier>features</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-features</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/features</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/features</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Upvotes: 2

khmarbaise
khmarbaise

Reputation: 97527

This behaviour is already given by default. But you should use a repository manager. You can simple deploy an artifact via mvn deploy usually having a SNAPSHOT release will go into the SNAPSHOT repository in case of a release it will go to the release repository.

Upvotes: 4

Related Questions