如何使用现有的pom.xml将第三方文件发布到远程maven仓库? [英] How to publish a 3rd party files to remote maven repo using an existing pom.xml?

查看:179
本文介绍了如何使用现有的pom.xml将第三方文件发布到远程maven仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些第三方罐子,我想上传到我的nexus maven repo,到目前为止,我已经找到了两种方法。

I have some third party jars that I want to upload to my nexus maven repo, and so far I have found two ways to do it.

  • Use the Nexus GUI
  • Use the instructions at http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html

mvn deploy:deploy-file -DgroupId=<group-id> \
  -DartifactId=<artifact-id> \
  -Dversion=<version> \
  -Dpackaging=<type-of-packaging> \
  -Dfile=<path-to-file> \
  -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
  -Durl=<url-of-the-repository-to-deploy>


我期待第三方图书馆经常更新一次当有安全更新/发布时,可能会更多四分之一。

I am expecting the 3rd party libraries to updated frequently say about once a quarter possibly more whenver there are security updates / releases.

上述两种方法都是手动的,您必须输入一个较长的命令或单击以实现它。我更喜欢一个非特定于产品或需要冗长命令行选项的简单解决方案。

Both of the two approaches above are manual you have to type a longish command or click around to make it happen. I would prefer a simple solution that is not product specific or requires lengthy command line options.

是否可以编写发布第3版的maven pom.xml派对.tar.gz只需做 mvn deploy

Is it possible to write a maven pom.xml that publishes a 3rd party .tar.gz just by doing mvn deploy

我正在使用maven 3.0.5

I am using maven 3.0.5

UPDATE 根据下面的radai答案为我工作的示例pom.xml。

推荐答案

我们在这里有类似的需求,保留非maven工件的标签并在我们的关系中更新它们。

we have a similar need here with keeping tabs of non-maven artifacts and updating them in our nexus.

我们的方式是不是在版本控制中有一个第三方项目,它存储非maven工件,每个工件都有自己的pom文件。

the way we did it is to have a "thirdparty" project in version control which stores the non-maven artifacts, each with its own pom file.

当你升级任何第三方时你覆盖第三方项目中的旧版本,将相关pom文件中的版本打包并运行mvn deploy将其放入我们的存储库。

when you upgrade any 3rd party you overwrite the old one in the thirdparty project, bunp the version in the associated pom file and run "mvn deploy" to put it into our repository.

build的pom文件导致* .tar.gz将有一个这样的pom:

a pom file for a "build" that results in a *.tar.gz will have a pom like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>myArtifact</artifactId>
    <packaging>pom</packaging> <!-- so it wont auto-create any *.jars or anything -->

    <build>
        <resources>
            <resource>
                <!-- put a configuration here to copy your artifact to /target -->
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy static resource files</id>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <!-- this creates your *.tar.gz -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Create final ZIP package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>true</appendAssemblyId>
                            <descriptors>
                                <descriptor>platform-assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

旁边有一个seembly描述符:
这个包装了一堆东西为*。 tar.gz,保留* .sh文件的可执行标志。您将需要编辑以满足您的需求

with an seembly descriptor alongside it: this one packages a bunch of stuff as *.tar.gz, retaining executable flags for *.sh files. you will need to edit to fit your needs

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>${envClassifier}</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>yourTargetDir</directory>
            <outputDirectory>/</outputDirectory>
            <excludes>
                <exclude>**/*.sh</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>yourTargetDir</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>**/*.sh</include>
            </includes>
            <fileMode>755</fileMode>
        </fileSet>
    </fileSets>
</assembly>

编辑:
如果你不需要提取/弄乱/。* .tar .gz工件,你有一个更简单的选项 - 使用构建帮助器maven插件的附加工件目标,只需将* .tar.gz附加到部署/安装中

if you dont need to extract/mess-with/ the *.tar.gz artifact that you have a much simpler option - use the build helper maven plugin's attach artifact goal to simply attach your *.tar.gz to be included in deployments/installs

您显然需要更新全部取决于这个新神器版本的步伐。

you obviously then need to update all of the paces that depend on this new artifact version.

这篇关于如何使用现有的pom.xml将第三方文件发布到远程maven仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆