它已經過2次周以來我已經成功地安裝的Nexus OSS,Maven和再搖籃能夠實現以下目標與搖籃或Maven下載依賴:上傳文物和購自Nexus庫
將文件上傳到公司的Nexus存儲庫,將它們鏈接在一起。所以這些文件必須保留一個鏈接,以便定義由其groupId/artifactId /版本填充的「包」。
下載由某些東西(如POM依賴模式)鏈接在一起的「包」(文件集)。
目前,我可以使用Maven和Gradle上傳Nexus上的一個文件。即使我使用Gradle在POM文件或build.gradle中指定了依賴項,我也無法立即下載包含所有依賴項的文件。
這裏的目標只是能夠定義一組按組/名稱/版本排序的組件,並且能夠一次下載所有組件。這就像版本包裝管理。
我看了2周,無法使用Maven或Gradle來實現這些目標。 請任何人都可以告訴我如何使用Maven或Gradle來完成這項工作?
這是POM文件,我用它來artifactA與artifactB在Maven的鏈接:
ArtifactA 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupA</groupId>
<artifactId>artifactA</artifactId>
<version>1.2.4</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Test Repository</name>
<url>http://localhost:7080/repository/content/repositories/releases/</url>
</repository>
</distributionManagement>
</project>
ArtifactB 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupA</groupId>
<artifactId>artifactB</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupA</groupId>
<artifactId>artifactA</artifactId>
<version>1.2.4</version>
<type>jar</type>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Test Repository</name>
<url>http://localhost:7080/repository/content/repositories/releases/</url>
</repository>
</distributionManagement>
</project>
一旦我已上傳然後B使用這些命令:
mvn deploy:deploy-file \
-Dfile=artifactA_package.jar \
-Dpackaging=jar \
-DpomFile=pomA1.2.4.xml \
-Durl=http://localhost:7080/repository/content/repositories/releases/ \
-DrepositoryId=nexus
mvn deploy:deploy-file \
-Dfile=artifactB_package.jar \
-Dpackaging=jar \
-DpomFile=pomB1.0.0.xml \
-Durl=http://localhost:7080/repository/content/repositories/releases/ \
-DrepositoryId=nexus
個
兩個文件以及上傳到我的Nexus倉庫裏面,即使artifactB POM文件指定一個依賴於A,當我使用這個腳本下載B:
mvn dependency:get \
-Dartifact=groupA:artifactB:1.0.0:jar \
-DremoteRepositories=nexus::default::http://localhost:7080/repository/content/repositories/releases/
的Maven只下載B,而不是A.即使我在B上使用此命令:
mvn dependency:resolve
它告訴我像「依賴:無」的東西。 因此Nexus或Maven不知道從B到A的依賴
搖籃也不起作用時,我用這個「的build.gradle」文件來達到我的目標:
apply plugin: 'maven'
repositories {
maven {
url "http://localhost:7080/repository/content/groups/public/"
}
}
artifacts {
archives file('artifactB_package.jar')
}
dependencies {
archives files('artifactA_package.jar')
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:7080/repository/content/repositories/releases/") {
authentication(userName: "deployment", password: "deployment123")
}
pom.project {
groupId "groupA";
artifactId "artifactB";
version "1";
dependencies {
dependency {
groupId "groupA";
artifactId "artifactA";
version "1";
}
}
}
}
}
}
只上傳B.
感謝您的回答。 我試圖實現的是使用他們的POM上傳一組文件來定義它們之間的依賴關係。 然後,我希望能夠只用一個解決依賴關係的命令來下載它們。 我試着用「mvn deploy」表示贊同,但它並不能幫助我在一個命令中下載A和B.即使我的POM文件定義了從B到A的依賴關係,Nexus或Maven似乎也沒有看到它...... – Yvan781 2014-10-03 14:40:50
以下是我在解析B上的依賴關係時所得到的結果:http://image.noelshack.com/fichiers/ 2014/40/1412347722-mvn-dependency-resolve-artifactb.png – Yvan781 2014-10-03 14:49:23
我明白了。我認爲有兩種選擇:一種是使用「mvn dependency:copy-dependencies」,它將所有需要的jar複製到你的目標文件夾中。另一個選擇是在構建過程中使用程序集插件將所需的所有內容打包到zip文件中,並將其放入nexus中:http://maven.apache.org/plugins/maven-assembly-plugin/ - 有一些默認程序集可用要做到這一點。 – wemu 2014-10-06 10:42:51