使用非标准的 Maven 存储库位置进行 gradle 构建



对于构建自动化,我们使用非标准的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"
}
}
} 

但格拉德尔仍然把事情放在~/.m2/repository.我该如何完成这项工作?

repositories {
maven {
url file('/some/place/repository')
}
} 

我认为您需要将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')
}
}

最新更新