我有以下POM结构:
./ foobar的共用/ pom.xml的 ./abc-window/pom.xml ./abc-datasource/pom.xml
abc-window pom.xml都如下:
<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>hu.abc.ringcore</groupId>
<artifactId>abc-window</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>abc-window</name>
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-datasource</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
abc-datasource pom.xml如下:
<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>hu.abc.ringcore</groupId>
<artifactId>abc-datasource</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>abc-datasource</name>
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-event</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-variable</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-variableintf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.foobar.ring</groupId>
<artifactId>RateSorszamIntf</artifactId>
<version>${ringcore-services.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
foobar-common pom.xml如下:
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<groupId>hu.foobar.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
<spring.version>3.1.2.RELEASE</spring.version>
<spring-security.version>2.0.6.RELEASE</spring-security.version>
<commons-logging.version>1.1.1</commons-logging.version>
<dom4j.version>1.6.1</dom4j.version>
<javaee-api.version>6.0</javaee-api.version>
<mycila-event.version>3.0</mycila-event.version>
<ringcore-services.version>1.3.4-SNAPSHOT</ringcore-services.version>
<commons-lang3.version>3.1</commons-lang3.version>
</properties>
</project>
我的问题是,如果我在mvn install
中执行abc-datasource
,则会根据预期从父pom属性中提取依赖项版本。但是,如果我从引用mvn install
的{{1}} abc-window
abc-datasource
然后版本未解决,我会:
[ERROR] Failed to execute goal on project abc-window: Could not resolve dependencies for project hu.abc.ringcore:abc-window:jar:1.0-SNAPSHOT: Failed to collect dependencies for [junit:junit:jar:4.10 (test), hu.abc.ringcore:abc-datasource:jar:1.0-SNAPSHOT (compile)]: Failed to read artifact descriptor for org.apache.commons:commons-lang3:jar:${commons-lang3.version}: Could not transfer artifact org.apache.commons:commons-lang3:pom:${commons-lang3.version} from/to central (http://repo.maven.apache.org/maven2): IllegalArgumentException: Illegal character in path at index 70: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/${commons-lang3.version}/commons-lang3-${commons-lang3.version}.pom
两个项目都有相同的父pom,为什么它不起作用??
答案 0 :(得分:4)
在父pom中使用dependencyManagment
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
在父pom中添加所有版本,并在子级中使用不带版本的依赖项
编辑
/pom.xml <-parent pom
/abc-window/pom.xml <-child module
/abc-datasource/pom.xml <-child module
和父pom应该包含
<project
...
<properties>
...
</properties>
<modules>
<module>abc-datasource</module>
<module>abc-window</module>
</modules>
<build>
<pluginManagment>
...
</pluginManagment>
</build>
<dependencyManagment>
...
</dependencyManagment>
</project>
答案 1 :(得分:1)
abc窗口中的父级列为:
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
abc-datasource中的父级列为:
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.ratesoft.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
所以,他们没有相同的groupId。