Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Pull code from SVN

I am migrating J2ee Project from Ant to Maven,
One of The ant tasks is to pull existing source from SVN Repository
Compile it, and add its jar to my current build as Jar

Is it possible to do the get the source and compile it in Maven?

Thank you!

<target name="checkoutBuild" description="Pulls code from SVN into the build directory">
    <exec executable="svn">
        <arg line="co ${svn.projecturl} ${project.build.root} -r ${svn.revision} --username ${svn.username} --password ${svn.password}"/>
    </exec>
</target>
like image 431
JavaSheriff Avatar asked Oct 24 '22 20:10

JavaSheriff


2 Answers

Yes, in a similar way as in Ant. Execute the svn command in exec-maven-plugin in one of pre-compile phases, perhaps in generate-sources. I'd try something like this (it's a brain-dump, may contain minor mistakes):

<build>
 <plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>...</version>
    <executions>
      <execution>
        <id>svn</id>
        <goals>
          <goal>exec</goal>
        </goals>
        <phase>generate-sources</phase>
      </execution>
    </executions>
    <configuration>
      <executable>svn</executable>
      <arguments>
        <argument>co</argument>
        <argument>${svn.projecturl}</argument>
        <argument>${project.build.root}</argument>
        ...
      </arguments>
    <configuration>
  </plugin>
 </plugins>
</build>

EDIT

Prunge's answer made me think — what do you want to really achieve? If the project is always to be the part of the build, a far better way would be to "mavenize" it (write a POM for it) and include it as a module/dependency.

If the SVN checkout is to be a one-time action, maybe it's better to leave it as it is, add the jar to the repository with mvn install:install-file (assigning a group id and artifact id), and use it as a dependency?

like image 114
MaDa Avatar answered Nov 02 '22 12:11

MaDa


You probably can, but it is not the 'Maven Way' of doing things.

Take a look at the Maven Release Plugin documentation.

What you'd typically do is:

  • Define your source control repository in your POM
  • Do a release:prepare which verifies everything is OK (no SNAPSHOT dependencies for release, etc.)
  • Do a release:peform. You can do this to a clean empty directory or even on a different machine that doesn't have the project checked out (release:perform can check out sources from source control by specifying an SCM URI on the command line).
like image 21
prunge Avatar answered Nov 02 '22 11:11

prunge