Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>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".</p> <pre><code> &lt;plugin&gt; &lt;inherited&gt;true&lt;/inherited&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;attach-artifacts&lt;/id&gt; &lt;phase&gt;deploy&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;attach-artifact&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;artifacts&gt; &lt;artifact&gt; &lt;file&gt;src/assembly/archive.xml&lt;/file&gt; &lt;type&gt;xml&lt;/type&gt; &lt;classifier&gt;archive&lt;/classifier&gt; &lt;/artifact&gt; &lt;/artifacts&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; </code></pre> <p>This artifact can be referenced directly by specifying the classifier and type in your dependency declaration. For example:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;my.group.id&lt;/groupId&gt; &lt;artifactId&gt;artifact-id&lt;/artifactId&gt; &lt;version&gt;1.0.0&lt;/version&gt; &lt;type&gt;xml&lt;/type&gt; &lt;classifier&gt;archive&lt;/classifier&gt; &lt;/dependency&gt; </code></pre> <hr> <p>If you are set on doing it this way, the <a href="http://maven.apache.org/scm/maven-scm-api/index.html" rel="nofollow noreferrer">Maven SCM API</a> provides an abstraction layer for common SCM providers and operations. The code below <a href="http://maven.apache.org/guides/plugin/guide-java-plugin-development.html" rel="nofollow noreferrer">can be added to a mojo</a>. 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.</p> <pre><code>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 = 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); } } } </code></pre> <p>Here's an example pom for the plugin, note the <em>maven-plugin</em> packaging:</p> <pre><code>&lt;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/maven-v4_0_0.xsd"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-svn-hack-plugin&lt;/artifactId&gt; &lt;packaging&gt;maven-plugin&lt;/packaging&gt; &lt;version&gt;0.0.1&lt;/version&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven&lt;/groupId&gt; &lt;artifactId&gt;maven-plugin-api&lt;/artifactId&gt; &lt;version&gt;2.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven&lt;/groupId&gt; &lt;artifactId&gt;maven-project&lt;/artifactId&gt; &lt;version&gt;2.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven.scm&lt;/groupId&gt; &lt;artifactId&gt;maven-scm-api&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven.scm&lt;/groupId&gt; &lt;artifactId&gt;maven-scm-provider-svnexe&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven.scm&lt;/groupId&gt; &lt;artifactId&gt;maven-scm-manager-plexus&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.codehaus.plexus&lt;/groupId&gt; &lt;artifactId&gt;plexus-utils&lt;/artifactId&gt; &lt;version&gt;1.5.1&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/project&gt; </code></pre> <p>Here's an example configuration that will check the file in during the package phase.</p> <pre><code>&lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-svn-hack-plugin&lt;/artifactId&gt; &lt;version&gt;0.0.1&lt;/version&gt; &lt;configuration&gt; &lt;connectionUrl&gt;scm:svn:http://svn.apache.org/svn/root/module&lt;/connectionUrl&gt; &lt;svnFile&gt;${project.build.directory}/${artifactId}-${version}-test.txt&lt;/svnFile&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;checkin-file&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;checkin-file&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; </code></pre> <p>Or at a pinch you could use the <a href="http://maven.apache.org/plugins/maven-antrun-plugin/" rel="nofollow noreferrer">antrun plugin</a> to invoke the <a href="http://ant.apache.org/antlibs/svn/index.html" rel="nofollow noreferrer">ant subversion library</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload