Maven:将单个工件提交到svn存储库

编程入门 行业动态 更新时间:2024-10-26 12:27:03
本文介绍了Maven:将单个工件提交到svn存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在部署生命周期阶段,如何将单个工件(如文件或目录)提交到svn存储库中的任意位置? 存储库,这里是指普通的Subversion存储库,而不是Subversion存储库中包含的Maven存储库!

How can I commit a single artifact like a file or a directory to an arbitrary location in a svn repository in the deploy lifecycle phase? With repository I mean a plain Subversion repository here, not a Maven repository held in a Subversion repository!

我已经评估了 wagon-svn ,但似乎可以使用将整个模块构建提交到Subversion存储库中的Maven存储库中.

I have already evaluated the wagon-svn but it seems it can just be used to commit a whole module build to a Maven repository held in a Subversion repository.

这是我的用例:我生成一个JAR文件,其中包括构建过程中的所有依赖项.这将在Python脚本中使用,因此不在Maven世界中.而且,我想始终在包含Python框架的存储库中的同一位置提供当前版本的JAR.

This is my use case: I generate a JAR-file including all dependencies during build. This is to be used in Python scripts, so outside the Maven world. And I want to provide the current release JAR always at the same location in the repository holding the Python framework.

推荐答案

在执行此操作之前,我会仔细考虑您这样做的原因. 不应将衍生的工件放到SCM中,因为它们可以轻松地重建,而是可以考虑将工件附加到构建中,以便将其与它一起部署.

Before you do this I would carefully consider your reasons for doing so. Derived artifacts shouldn't be put into SCM as they can easily be rebuilt, instead you could consider attaching the artifact to your build so it is deployed alongside it.

这可以通过build-helper-maven-plugin完成.下面的示例配置会将src/assembly/archive.xml附加为带有分类器"archive"的附加工件.

This can be done with the build-helper-maven-plugin. The example config below will attach src/assembly/archive.xml as an additional artifact with the classifier "archive".

<plugin> <inherited>true</inherited> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>attach-artifacts</id> <phase>deploy</phase> <goals> <goal>attach-artifact</goal> </goals> <configuration> <artifacts> <artifact> <file>src/assembly/archive.xml</file> <type>xml</type> <classifier>archive</classifier> </artifact> </artifacts> </configuration> </execution> </executions> </plugin> </plugins>

可以通过在您的依赖项声明中指定分类器和类型来直接引用此工件.例如:

This artifact can be referenced directly by specifying the classifier and type in your dependency declaration. For example:

<dependency> <groupId>my.group.id</groupId> <artifactId>artifact-id</artifactId> <version>1.0.0</version> <type>xml</type> <classifier>archive</classifier> </dependency>

如果您打算这样做,则 Maven SCM API 为常见的SCM提供程序和操作提供了一个抽象层.可以将>下面的代码添加到mojo 中.它期望提供两个参数,即要提交给Subversion的文件和scm url.绑定到项目后,它将把文件提交到Subversion存储库.

If you are set on doing it this way, the Maven SCM API provides an abstraction layer for common SCM providers and operations. The code below can be added to a mojo. It expects to be provided two parameters, the file to be committed to Subversion and the scm url. When bound to your project, it will commit the file to the Subversion repository.

package name.seller.rich; import java.io.File; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scmmand.add.AddScmResult; import org.apache.maven.scm.manager.ScmManager; import org.apache.maven.scm.provider.ScmProvider; import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; import org.apache.maven.scm.repository.ScmRepository; /** * @goal checkin-file */ public class SVNCheckinMojo extends AbstractMojo { /** * @component * @required */ private ScmManager manager; /** * @component * @required */ private ScmProvider provider; /** * @parameter * @required */ private String connectionUrl; /** * @parameter * @required */ private File svnFile; /** * Obtain the SVN repository. */ public ScmRepository getRepository() throws MojoExecutionException { try { ScmRepository repository = manager.makeScmRepository(connectionUrl); if (!(repository.getProviderRepository() instanceof SvnScmProviderRepository)) { throw new MojoExecutionException( "the scm provider is not an SVN provider"); } return repository; } catch (Exception e) { throw new MojoExecutionException( "Unable to obtain SCM repositorys", e); } } public void execute() throws MojoExecutionException, MojoFailureException { ScmRepository repository = getRepository(); File dir = svnFile.getParentFile(); File file = new File(svnFile.getName()); ScmFileSet fileSet = new ScmFileSet(dir, file); try { AddScmResult result = provider.add(repository, fileSet); if (!result.isSuccess()) { throw new MojoExecutionException("unable to add file \"" + svnFile + "\" to SCM URL \"" + connectionUrl + "\""); } } catch (ScmException e) { throw new MojoExecutionException( "failed to commit file to repository", e); } } }

这是该插件的示例pom,请注意 maven-plugin 包装:

Here's an example pom for the plugin, note the maven-plugin packaging:

<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-svn-hack-plugin</artifactId> <packaging>maven-plugin</packaging> <version>0.0.1</version> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.apache.maven.scm</groupId> <artifactId>maven-scm-api</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.apache.maven.scm</groupId> <artifactId>maven-scm-provider-svnexe</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.apache.maven.scm</groupId> <artifactId>maven-scm-manager-plexus</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>1.5.1</version> </dependency> </dependencies> </project>

这是一个示例配置,它将在打包阶段将文件检入.

Here's an example configuration that will check the file in during the package phase.

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-svn-hack-plugin</artifactId> <version>0.0.1</version> <configuration> <connectionUrl>scm:svn:svn.apache/svn/root/module</connectionUrl> <svnFile>${project.build.directory}/${artifactId}-${version}-test.txt</svnFile> </configuration> <executions> <execution> <id>checkin-file</id> <phase>package</phase> <goals> <goal>checkin-file</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

或者在紧要关头,您可以使用 antrun插件进行调用 ant Subversion库

Or at a pinch you could use the antrun plugin to invoke the ant subversion library

更多推荐

Maven:将单个工件提交到svn存储库

本文发布于:2023-11-03 06:49:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工件   Maven   svn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!