Search code examples
maven

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?


Solution

  • 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>