我习惯于构建一个我需要在本地仓库中安装的库,以便在其他项目中使用。
我已在项目mvn install
中尝试basedir
。
我已经尝试maven-install-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<groupId>somegroup</groupId>
<artifactId>someartifact</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}/target/someartifact.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
正确安装了jar,但是当我添加依赖
时<dependency>
<groupId>somegroup</groupId>
<artifactId>someartifact</artifactId>
<version>1.0</version>
</dependency>
列出的其他项目未显示过渡依赖项。
当运行项目测试失败且NoClassDefFoundError
转换依赖项时,会出现问题。
如何解决这个问题?
编辑:
父项目pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>somegroup</groupId>
<artifactId>parentartifact</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>thirdpartygroup</groupId>
<artifactId>missingartifact</artifactId>
<version>x.x.x</version>
</dependency>
</dependencies>
<build>
<defaultGoal>compile</defaultGoal>
<sourceDirectory>
${project.basedir}/src/main/java
</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>false</verbose>
<debug>false</debug>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<finalName>parentartifact</finalName>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
儿童项目pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>somegroup</groupId>
<artifactId>someartifact</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>somegroup</groupId>
<artifactId>parentartifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<defaultGoal>compile</defaultGoal>
<directory>target</directory>
<finalName>${artifactId}-${version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>false</verbose>
<debug>false</debug>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
答案 0 :(得分:1)
install-file
目标是将外部jar文件安装到本地存储库中。它并不意味着用于安装由Maven构建的项目生成的工件。应该使用maven-install-plugin的install
目标安装此类项目。此目标会自动安装项目的pom(定义依赖项)以及存储库中的工件。
它还有一个优点,就是不需要在pom中配置install-plugin。它始终是构建的一部分。只需在你的pom中没有配置maven-install-plugin就可以调用mvn install
。