Maven - 从 SVN 提取代码

发布于 2024-12-11 13:17:49 字数 479 浏览 0 评论 0原文

我正在将 J2ee 项目从 Ant 迁移到 Maven,
ant 任务之一是从 SVN 存储库中提取现有源
编译它,并将其 jar 添加到我当前的构建中作为 Jar

是否可以获取源代码并在 Maven 中编译它?

谢谢你!

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

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>

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

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

发布评论

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

评论(2

云淡风轻 2024-12-18 13:17:49

是的,与 Ant 中的方式类似。在预编译阶段之一(可能是在生成源中)执行 exec-maven-plugin 中的 svn 命令。我会尝试这样的事情(这是一个大脑转储,可能包含小错误):

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

编辑

普朗格的回答让我思考 - 你真正想要实现什么?如果项目始终是构建的一部分,那么更好的方法是“mavenize”它(为其编写 POM)并将其包含为模块/依赖项。

如果 SVN 签出是一次性操作,也许最好保持原样,使用 mvn install:install-file 将 jar 添加到存储库(分配组 ID 和工件) id),并将其用作依赖项?

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?

弃爱 2024-12-18 13:17:49

你也许可以,但这不是做事的“Maven 方式”。

查看 Maven 发布插件 文档。

您通常要做的是:

  • 在 POM 中定义 源代码控制存储库
  • 执行 < a href="http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html" rel="nofollow">release:prepare 验证一切正常(没有快照依赖项发布等)
  • 执行 release:peform。您可以对一个干净的空目录执行此操作,甚至可以在未签出项目的另一台计算机上执行此操作(release:perform 可以通过在命令行上指定 SCM URI 从源代码管理中签出源代码)。

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).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文