gpt4 book ai didi

gradle - 如何避免在父项目中重复子存储库

转载 作者:行者123 更新时间:2023-12-03 03:18:18 25 4
gpt4 key购买 nike

我有一个具有以下结构的多项目构建:

Root project 'just-another-root-project'
+--- Project ':producer'
\--- Project ':consumer'

settings.gradle文件:
rootProject.name = 'just-another-root-project'
include 'consumer', 'producer'

...连接创建的模块。
producer.gradle文件:
plugins {
id 'java-library'
}

group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}

dependencies {
implementation 'com.sun:tools:1.7.0.13'
}

...具有未在 Maven Central 中发布的外部依赖项 ( com.sun.tools ),因此我添加了指向 Nuiton 存储库的链接。
consumer.gradle文件:
plugins {
id 'java'
}

group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
annotationProcessor project(':producer')
}

上面描述的构建不起作用!为了做到这一点,我被迫从 producer.gradle 复制所有存储库进入 consumer.gradle . 那么问题是如何在没有过多依赖重复的情况下构建根项目? 如何以正确的方式做到这一点?感谢您的任何回答或提示:)

更新 1 :

尝试使用上面显示的文件构建项目时出现以下错误:
FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':consumer:compile'.
> Could not find com.sun:tools:1.7.0.13.
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.pom
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.jar
Required by:
project :consumer > project :producer

最佳答案

您可以像这样直接在根项目中配置存储库:

根项目 build.gradle :

// configure repositories for all projects
allprojects {
repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}
}

编辑(来自您对其他回复的评论)

您也可以只定义 mavenCentral()根项目级别的存储库(它将添加到所有项目的存储库)并配置 http://maven.nuiton.org/release仅适用于生产者子项目的存储库:

根项目
repositories {
// will apply to all project
mavenCentral()
}

生产者项目
 repositories {
maven {
url 'http://maven.nuiton.org/release/'
}
// mavenCentral inherited from root project
}

消费项目
// no need to re-define repositories here.

关于gradle - 如何避免在父项目中重复子存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52445020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com