Maven:如何使用部署文件和自定义 Wagon 进行部署

发布于 2024-07-14 13:20:37 字数 218 浏览 6 评论 0原文

我正在尝试使用自定义 Maven Wagon 扩展将 jar 部署到我自己的存储库。 我是否可以在 settings.xml 中进行配置,使其识别与特定货车一起使用的自定义 url 方案,或者我是否必须始终修改 pom 文件以包含货车扩展?


使用部署文件时不需要有基础 pom 或任何可用的 pom。 Settings.xml 是唯一保证存在的地方,但我不知道如何使用它来定义扩展。

I'm trying to use a custom maven wagon extension to deploy a jar to my own repository. Can I somehow configure in settings.xml that it recognizes the custom url scheme to be used with the specific wagon or do I have to always modify pom files to contain the wagon extension?


There doesn't need to be a base pom or any pom available when using the deploy-file. Settings.xml is the only place which is guaranteed to be there, but I can't figure out how to use it to define extensions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

樱娆 2024-07-21 13:20:37

我不知道上面的评论是否为Brian Fox 在 2013 年仍然有效。但最终我不得不在我尝试上传工件以启用 wagon 构建扩展的目录中创建一个最小的 pom.xml。

我必须将 groupId、artifactId 和 version 添加到 pom.xml,这样 Maven 就不会抱怨,尽管我将它们提供给了命令行上的部署文件目标(不过我猜部署文件只会关心命令行参数)

<project 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>
<groupId>your-groupId</groupId>
<artifactId>your-artifactId</artifactId>
<version>your-version</version>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-ssh</artifactId>
      <version>2.4</version>
    </extension>
  </extensions>
</build>
</project>

:这个简单的“pom.xml”就位,我最终可以使用 scp 作为协议来执行部署文件:

mvn deploy:deploy-file -Durl=scp://shell.sourceforge.net:/home/project-web/... -DrepositoryId=repoId -Dfile=my-file.jar -DgroupId=your-groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar

I don't know if the comment above by Brian Fox is still valid in 2013. But in the end I had to create a minimal pom.xml in the directory where I tried to upload the artifact to enable the wagon build extension.

I had to add groupId, artifactId and version to the pom.xml so that Maven would not complain although I provided them to the deploy-file goal on the commandline (I guess deploy-file would only care about the commandline parameters though):

<project 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>
<groupId>your-groupId</groupId>
<artifactId>your-artifactId</artifactId>
<version>your-version</version>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-ssh</artifactId>
      <version>2.4</version>
    </extension>
  </extensions>
</build>
</project>

With this simple "pom.xml" in place I could execute the deploy-file finally using scp as the protocol:

mvn deploy:deploy-file -Durl=scp://shell.sourceforge.net:/home/project-web/... -DrepositoryId=repoId -Dfile=my-file.jar -DgroupId=your-groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar
在梵高的星空下 2024-07-21 13:20:37

好的,好的,更正一下:您不能在 settings.xml 中定义的 中定义 元素。 您可以在 settings.xml 中激活配置文件,但在 base-pom 中定义它。

抱歉,我能想到的唯一其他方法(可能是您正在寻找的方法)是将扩展 jar 直接复制到 $M2_HOME/lib 下。 所有 $M2_HOME/lib/*.jar 都放在类路径中,因此这实际上必须具有与 相同的效果。

然而,该扩展更好,因为您可以更轻松地控制使用哪个版本的扩展(例如通过 base-pom)。

好的,尝试将扩展 jar 复制到下面

    $M2_HOME/lib

OK, ok, a correction: you cannot define the <build> element inside a <profile> defined in settings.xml. You could activate the profile in settings.xml, but define it in your base-pom.

Sorry, the only other way I could think of (probably what are you looking for), is to copy the extension jar directly under $M2_HOME/lib. All $M2_HOME/lib/*.jar are put in the classpath, so this must virtually have the same effect as an <extension>.

The extension however is better, because you can more easily control which version of the extension is used (e.g. trough the base-pom).

OK just try copying the extension jar under

    $M2_HOME/lib
染柒℉ 2024-07-21 13:20:37

您需要 将 wagon 扩展添加到您的顶级 pom.xml 。 大多数环境在所有项目的顶部都有一个公司的 pom(最佳实践),因此这对于个人开发人员来说通常不会太痛苦 - 他们只是从公司的 pom 继承。

<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-scm</artifactId>
      <version>1.0-alpha-7-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-manager-plexus</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-provider-svnexe</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
  </extensions>
</build>
<distributionManagement>
  <site>
    <id>my.svn.server</id>
    <url>scm:svn:https://[email protected]/svn/root/module</url>
  </site>
</distributionManagement>

我相信,当您注册提供商时,它也会注册协议模式。 您可以在此处查看现有提供程序的完整列表

我相信是 getScmType() 方法注册了扩展,但我不能 100% 确定。

/** {@inheritDoc} */
public String getScmType()
{
    return "git";
}

可以在此处找到 Git 提供程序源的链接。

You need to add the wagon extension to your top level pom.xml. Most environments have a corporate one at the top of all their projects (best practice), so this generally isn't too painful for individual developers -- they just inherit from the corporate pom.

<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-scm</artifactId>
      <version>1.0-alpha-7-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-manager-plexus</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-provider-svnexe</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
  </extensions>
</build>
<distributionManagement>
  <site>
    <id>my.svn.server</id>
    <url>scm:svn:https://[email protected]/svn/root/module</url>
  </site>
</distributionManagement>

When you register your provider, it also registers the protocol pattern as well I believe. You can see a full list of the existing providers here.

I believe it is the getScmType() method that registers the extension, but I'm not 100% certain.

/** {@inheritDoc} */
public String getScmType()
{
    return "git";
}

The link to the Git provider's source can be found here.

浮世清欢 2024-07-21 13:20:37

siddhadev 是对的,但还有一些额外的事情......
(我会把它放在评论中,但我没有足够的声誉)

你可以通过将 JAR 放在以下位置来将它们干净地分开:
$M2_HOME/lib/ext

您需要所有依赖项,因此请执行以下操作:

  1. cd ~/.m2/repository/org/apache/maven/wagon/wagon-ssh-external/2.2
  2. cp wagon-ssh-external-2.2。 jar $M2_HOME/lib/ext
  3. cp wagon-ssh-external-2.2.pom pom.xml
  4. mvn 依赖项:复制依赖项 -DoutputDirectory=$M2_HOME/lib/ext

siddhadev is right, but there are few additional things...
(I'd put this in a comment but I don't have enough reputation)

You can keep your JARs cleanly separated by putting them under:
$M2_HOME/lib/ext

You need all of the dependencies, so do something like:

  1. cd ~/.m2/repository/org/apache/maven/wagon/wagon-ssh-external/2.2
  2. cp wagon-ssh-external-2.2.jar $M2_HOME/lib/ext
  3. cp wagon-ssh-external-2.2.pom pom.xml
  4. mvn dependency:copy-dependencies -DoutputDirectory=$M2_HOME/lib/ext
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文