对于构建自动化,我们使用非标准的Maven存储库位置,该位置在这样的设置文件中定义:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/some/place/repository</localRepository>
... other stuff
</settings>
Maven被作为mvn --settings settings.xml
调用。
现在我们有一个额外的项目,该项目使用gradle。我如何最好地说服gradle使用相同的非标准存储库来检查它依赖的软件包,并发布其他(maven)项目可能依赖的工件?
build.gradle
文件当前如下所示:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'maven-publish'
group = 'com.example'
version = '1.3.4'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
....
}
task uberJar(type: Jar) {
description = 'Make JAR with all the dependencies included'
classifier = 'uber'
dependsOn configurations.runtime
from sourceSets.main.output
from { configurations.runtime.collect { it.directory ? it : zipTree(it) } }
}
task sourceJar(type: Jar) {
description = 'Make JAR of all the source files'
classifier = 'sources'
from sourceSets.main.allSource
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourceJar
artifact jar
}
}
}
我尝试在https://docs.gradle.org/current/userguide/publishing_maven.html的每个描述中添加此内容
publishing {
repositories {
maven {
url "/some/place/repository"
}
}
}
,但是gradle仍然会将内容放入~/.m2/repository
中。我该如何进行这项工作?
答案 0 :(得分:1)
repositories {
maven {
url file('/some/place/repository')
}
}
答案 1 :(得分:1)
我认为您需要将repositories
声明和publications
放在同一publishing
块中,如下所示:
publishing {
repositories {
maven {
url file('/some/place/repository')
}
}
publications {
maven(MavenPublication) {
from components.java
artifact sourceJar
artifact jar
}
}
}
从@ lance-java的答案中另外添加代码片段,以使自定义存储库中的工件可用于其他项目:
repositories {
mavenLocal()
mavenCentral()
maven {
url file('/some/place/repository')
}
}