【问题标题】:maven-deploy-plugin repositorymaven-deploy-plugin 存储库
【发布时间】:2013-03-19 07:58:38
【问题描述】:

我想使用 maven-deploy-plugin 部署文件。目前我的 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>

我想根据版本在快照和发布存储库之间进行更改。如果项目版本为 1-SNAPSHOT,则文件应部署到快照存储库,如果项目版本为 1.0,则文件应部署到发布存储库。但是 maven-deploy-plugin 硬编码呢?

【问题讨论】:

    标签: maven


    【解决方案1】:

    默认情况下已经给出了这种行为。但是你应该使用repository manager。您可以通过 mvn deploy 简单地部署工件,通常有一个 SNAPSHOT 版本将进入 SNAPSHOT 存储库,以防发布它会进入发布存储库。

    【讨论】:

    • 我不确定它是默认给出的。该项目已经部署了一个 jar 和 pom。是否有另一种自动部署 XML 文件的方法?
    【解决方案2】:

    我最终得到的解决方案是使用 build-helper-maven-plugin 和 maven-resources-plugin。此设置意味着与 jar 和 pom 以及项目一起部署一个 xml 文件,该文件可以在 maven 存储库中作为 project/xml/features 引用。

    相关pom插件:

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

    【讨论】:

    • 很好的答案。我最终使用了您的解决方案。看起来我们都在上传 Karaf features.xml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2015-04-09
    • 1970-01-01
    • 2011-06-25
    • 2018-11-03
    相关资源
    最近更新 更多