使用 Maven 只是为了获取一些库 jar

发布于 2024-10-10 00:13:59 字数 176 浏览 0 评论 0原文

我们在构建过程中使用 ANT,并且没有计划在不久的将来改变这一点。

是否可以使用 Maven 只获取常见的开源 jar 文件(例如 Log4J、SWT、JFace)并将它们放在我们项目的正确位置,这样我们就不必将它们存储在我们的版本控制——最好不要在主目录中创建典型的 Maven 缓存?

We are using ANT for our build process and don't have plans to change this in the near future.

Is it possible to use Maven to just fetch common Open Source jar files (e.g. Log4J, SWT, JFace) and put them in the right location of our project, so we don't have to store them in our version control — preferable without creating the typical Maven-cache in the home directory?

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

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

发布评论

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

评论(4

暗喜 2024-10-17 00:13:59

不不不大家!

如果您使用 Ant,使用 Maven 存储库下载 jar 依赖项的最佳方法是将 Ivy 与 Ant 结合使用。这正是 Ivy 的用途。

安装 Ivy 并开始使用当前的 Ant 项目很简单。如果您使用 Nexus 和 Artifactory 作为本地 Maven 存储库,它可以与 Nexus 和 Artifactory 配合使用。

看看常春藤。这可能正是您想要的。

NO NO NO Everyone!

If you're using Ant, the best way to use Maven repositories to download jar dependencies is to use Ivy with Ant. That's exactly what Ivy is for.

Installing Ivy and getting to work with current Ant projects is simple to do. It works with Nexus and Artifactory if you use those as your local Maven repositories.

Take a look at Ivy. It is probably exactly what you want.

荒人说梦 2024-10-17 00:13:59

org.life.java 的答案,我不会执行mvn install

相反,我会在 pom.xml 中添加以下内容:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

现在您只需要执行 mvngenerate-sources,这比完整的 mvn install 快得多,并且所有依赖项都会被复制到指定目录。


哦,顺便说一句,这不是 Apache Ivy 的意思吗?扩展Ant以了解Maven的依赖管理?

In variation of org.life.java's answer, I would not do mvn install.

Instead, in the pom.xml I would add the following bit:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Now you just need to do mvn generate-sources, which is a lot faster than the full mvn install, and all dependencies will be copied to the specified directory.


Oh btw, isn't that what Apache Ivy is about? Extending Ant to understand Maven's dependency management?

旧人哭 2024-10-17 00:13:59

有可能,您应该使用 maven-ant-tasks

特别是它的 dependency ant 任务。通过此设置,不需要安装 Maven。

<?xml version="1.0" encoding="UTF-8"?>
<project
  name="download-dependency"
  basedir="."
  default="download-dependency"
  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
  <target name="download-dependency">

    ... define properties ...

    <taskdef
      resource="org/apache/maven/artifact/ant/antlib.xml"
      uri="antlib:org.apache.maven.artifact.ant"
    />

    <artifact:dependencies>
      <localRepository path="${local-repo.dir}"/>
      <remoteRepository id="central" url="${repository-uri}"/>
      <dependency
        groupId="${groupId}"
        artifactId="${artifactId}"
        version="${version}"
        type="${type}"
        classifier="${classifier}"
        scope="runtime"
      />
    </artifact:dependencies>
  </target>
</project>

您应该签入项目的唯一二进制文件是 maven-ant-tasks.jar

实际上在我们的项目中我使用了 Sonatype Nexus ( 文档 ) Maven 存储库管理器,用于集中对不同存储库的访问,甚至维护一些我们环境特有的二进制文件。在 Nexus 的帮助下,我只需从已知 URL 中使用 ant 的 任务获取 maven-ant-tasks.jar 即可。您不必使用 Nexus,但它可以大大加快构建速度,因为它将二进制文件缓存在靠近开发人员计算机的位置。

It's possible, you should use maven-ant-tasks.

In particular its dependencies ant task. With this setup no Maven install is required.

<?xml version="1.0" encoding="UTF-8"?>
<project
  name="download-dependency"
  basedir="."
  default="download-dependency"
  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
  <target name="download-dependency">

    ... define properties ...

    <taskdef
      resource="org/apache/maven/artifact/ant/antlib.xml"
      uri="antlib:org.apache.maven.artifact.ant"
    />

    <artifact:dependencies>
      <localRepository path="${local-repo.dir}"/>
      <remoteRepository id="central" url="${repository-uri}"/>
      <dependency
        groupId="${groupId}"
        artifactId="${artifactId}"
        version="${version}"
        type="${type}"
        classifier="${classifier}"
        scope="runtime"
      />
    </artifact:dependencies>
  </target>
</project>

The only binary you should check into your project is maven-ant-tasks.jar.

Actually in our project I used Sonatype Nexus ( documentation ) Maven repository manager to centralize access to different repositories and even maintain some binaries unique to our environment. With Nexus' help I just fetch maven-ant-tasks.jar with ant's <get> task from a known URL. You don't have to use Nexus, but it greatly speeds up builds, because it caches binaries close to your developer's machines.

蒲公英的约定 2024-10-17 00:13:59

艾维就是这么做的,
当它自我引导时:
http://ant.apache.org/ivy/history/latest -milestone/samples/build.xml

<property name="ivy.install.version" value="2.0.0-beta1"/>
<property name="ivy.jar.dir" value="lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<target name="resolve" unless="skip.download">
    <mkdir dir="${ivy.jar.dir}"/>
    <echo message="installing ivy..."/>
    <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target> 

Ivy does just this,
when it bootstraps itself:
http://ant.apache.org/ivy/history/latest-milestone/samples/build.xml

<property name="ivy.install.version" value="2.0.0-beta1"/>
<property name="ivy.jar.dir" value="lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<target name="resolve" unless="skip.download">
    <mkdir dir="${ivy.jar.dir}"/>
    <echo message="installing ivy..."/>
    <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文