dig*_*nie 61 dependencies maven-2 pom.xml
如果我要使用不在maven公共存储库中的第三方库,那么将它作为项目的依赖项包含在内的最佳方法是什么,以便当其他人签出我的代码时它仍然可以构建?
即
我的应用程序"A"依赖于公共存储库中不存在的jar"B".但是,我希望添加"B"作为对"A"的依赖,这样当世界另一端的人可以查看代码并仍然能够构建"A"时
not*_*oop 60
您可以自己安装项目.
或者您可以使用以下system范围:
<dependency>
<groupId>org.group.project</groupId>
<artifactId>Project</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/project-1.0.0.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
systemPath需要项目的绝对路径.为了简化操作,如果jar文件位于存储库/项目中,则可以使用${basedir}绑定到项目根目录的属性.
Dom*_* D. 16
如果您的父项目具有处于这种情况的模块(需要不在存储库中的依赖项),您可以设置您的父项目以使用exec-maven-plugin插件来自动安装您的相关文件.例如,我必须使用authorize.net jar文件执行此操作,因为它不公开.
父POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<inherited>false</inherited>
<executions>
<execution>
<id>install-anet</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>install:install-file</argument>
<argument>-Dfile=service/lib/anet-java-sdk-1.4.6.jar</argument>
<argument>-DgroupId=net.authorize</argument>
<argument>-DartifactId=anet-java-sdk</argument>
<argument>-Dversion=1.4.6</argument>
<argument>-Dpackaging=jar</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,jar的位置位于"service"模块的lib文件夹中.
当服务模块进入验证阶段时,jar将在本地存储库中可用.只需在父pom中设置groupid,artifact等的方式引用它.例如:
<dependency>
<groupId>net.authorize</groupId>
<artifactId>anet-java-sdk</artifactId>
<version>1.4.6</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
rpe*_*rez 15
使用系统范围可能有效,但即使在Maven规范中也不建议使用.它不便携.
来自Maven的书:
system-除了必须在本地文件系统上提供JAR的显式路径之外,系统范围与提供的类似.这旨在允许编译可能是系统库一部分的本机对象.假定工件始终可用,并且不在存储库中查找.如果将范围声明为system,则还必须提供systemPath元素.请注意,不建议使用此范围(您应始终尝试在公共或自定义Maven存储库中引用依赖项).
最好的方法是安装到本地存储库或企业存储库,以便所有对等方都可以访问.
如果您使用的是Nexus等存储库管理器,这非常简单.
| 归档时间: |
|
| 查看次数: |
39338 次 |
| 最近记录: |