Maven: Commit single artifact to svn repository

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

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!

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.

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.

回答1:

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.

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

       true     org.codehaus.mojo     build-helper-maven-plugin                     attach-artifacts         deploy                    attach-artifact                                                               src/assembly/archive.xml                 xml                 archive                                                     

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

   my.group.id   artifact-id   1.0.0   xml   archive 

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.scm.command.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         
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!