当我使用 pom 文件的属性部分中定义的键的依赖项的版本时,不会下载依赖项,但是当我对依赖项的版本进行硬编码时,会下载依赖项。
<properties>
<cucumber-version>1.2.4</cucumber-version>
<junit-version>1.2.4</junit-version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>{cucumber-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>{cucumber-version}</version>
<scope>test</scope>
</dependency>
<dependencies>
对于上面的块,当我运行mvn clean test然后在控制台中,错误显示为:-
[ERROR] Failed to execute goal on project MavenCucumber: Could not resolve dependencies for project com.manish.cucumber:MavenCucumber:jar:1.0-SNAPSHOT: Failed to collect dependencies at info.cukes:cucumber-java:jar:{junit-version}: Failed to read artifact descriptor for info.cukes:cucumber-java:jar:{junit-version}: Could not transfer artifact info.cukes:cucumber-java:pom:{junit-version} from/to central (http://repo.maven.apache.org/maven2): Illegal character in path at index 61: http://repo.maven.apache.org/maven2/info/cukes/cucumber-java/{cucumber-version}/cucumber-java-{cucumber-version}.pom -> [Help 1]
完成 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">4.0.0 com.manish.cucumber MavenCucumber jar 1.0-SNAPSHOT MavenCucumber http://maven.apache.org
<properties>
<cucumber-version>1.2.4</cucumber-version>
<junit-version>1.2.4</junit-version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>{junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>{junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<argLine>-Duser.language=en</argLine>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
我使用的 Maven 版本是 Maven-3
为什么 maven 尝试从 url 获取依赖项,如下所示:-
repo.maven.apache.org/maven2/info/cukes/cucumber-java/{cucumber-version}/cucumber-java-{cucumber-version}.pom
为什么不将 {cucumber-version} 替换为属性标签中定义的 1.2.4