用于安装多个第三方商业库的Maven POM文件

Svi*_*ish 19 maven-2 maven-3 maven

我有一堆项目依赖于一组商业第三方库.我们目前没有公司存储库,因此我必须在我自己的本地存储库中安装库.

mvn install:installFile -Dpackaging=jar -Dfile=<file> -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version>为每个文件运行相当繁琐.可以创建一个bat文件,但有没有办法使用maven这样做?

我正在考虑一个包含所有jar和单个pom文件的项目,其中包含所有组ID,工件ID,版本和文件名,然后是mvn install在该项目中运行的可能性,或者沿着这些行的东西.

有可能这样吗?


注意:我使用的是Maven 3,但Maven 2兼容的解决方案也不错.

Eug*_*hov 42

您可以使用Maven安装插件的多个执行安装文件目标来创建pom.xml .假设这些文件已在某处本地可用(或者您可以使用Wagon插件下载它们).

  <project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.somegroup</groupId>
    <artifactId>my-project</artifactId>
    <version>1.0</version>

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.4</version/>
          <executions>
            <execution>
              <id>install1</id>
              <phase>package</phase>
              <goals>
                <goal>install-file</goal>
              </goals>
              <configuration>
                <file>lib/your-artifact-1.0.jar</file>
                <groupId>org.some.group</groupId>
                <artifactId>your-artifact</artifactId>
                <version>1.0</version>
                ... other properties
              </configuration>
            </execution>
            <execution>
              <id>install2</id>
              <phase>package</phase>
              <goals>
                <goal>install-file</goal>
              </goals>
              ... etc

            </execution>
            ... other executions
          </executions>
        </plugin>
      </plugins>
    </build>
  </project>
Run Code Online (Sandbox Code Playgroud)

所以,上面的pom片段mvn package应该可以做到.

有很好的Maven POM教程POM参考.

  • 此pom.xml文件仅安装一个工件.该问题需要多个工件. (5认同)

Svi*_*ish 12

最近发现了一种新的解决方案.基本上,您可以在项目中创建一个本地存储库,可以使用其余的源代码进行检查.在此博客:http://www.geekality.net/?p = 2376 .

要点是将依赖项部署到项目中的文件夹.

mvn deploy:deploy-file
    -Durl=file:///dev/project/repo/
    -Dfile=somelib-1.0.jar
    -DgroupId=com.example
    -DartifactId=somelib
    -Dpackaging=jar
    -Dversion=1.0
Run Code Online (Sandbox Code Playgroud)

然后简单地让Maven知道它并通过你的正常使用依赖声明pom.xml.

<repositories>
    <repository>
        <id>project.local</id>
        <name>project</name>
        <url>file:${project.basedir}/repo</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.example</groupId>
    <artifactId>somelib</artifactId>
    <version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

不是非常Maven'y,但它的工作原理以及后来将依赖项移动到公司存储库应该非常简单.