Gradle 渐变:禁用自动下载依赖项
我在Eclipse中创建了一个Gradle项目,并创建了以下Gradle 渐变:禁用自动下载依赖项,gradle,Gradle,我在Eclipse中创建了一个Gradle项目,并创建了以下build.Gradle // Apply the java plugin to add support for Java apply plugin: 'java' // In this section you declare where to find the dependencies of your project repositories { // Use 'jcenter' for resolving your dep
build.Gradle
// Apply the java plugin to add support for Java
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.18'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
然后,下载slf4j
模块并将其缓存在~/.gradle
中
但是我不想要它!!我的Linux发行版在存储库中包含slf4j
,因此我宁愿使用pacman
/apt get
/等来安装所需的模块
我宁愿Gradle错误地指出模块丢失,或者仅在指定标志时下载所需的模块
如何才能防止Gradle过于热心?如果您不想从jcenter下载任何内容,请不要将jcenter添加为存储库。如果不定义任何存储库,gradle将不会下载任何内容。但是您必须手动下载和处理依赖项,而jcenter/Maven central是查找此类Java依赖项的最佳位置。用apt来做这件事是一个可怕的想法。为什么是一个可怕的想法?我的发行版的软件包管理器在记住安装了什么、它位于何处、占用了多少空间方面比我做得更好。apt对于处理使用apt的Linux机器的本机可执行软件包很有用。这不是您在这里要做的。您正在尝试处理Java项目的依赖项。这就是像gradle这样的Java依赖项管理工具的用途。像gradle这样的构建工具的全部意义在于,任何人都应该能够获取项目的源代码(在Windows、Mac、任何Linux版本上),执行
gradlew build
,下载依赖项并构建项目。好的,这样我就可以配置本地gradle安装,以便在下载之前询问我,其他人都可以gradlew构建。我有一个本地的gradle安装,这将是毫无意义的,因为gradlew
下载gradle
二进制文件这就是gradlew
的目的-在对系统一无所知的情况下进行构建。但当我在系统上拥有一个完全控制权时……因为一个jar文件不足以知道它是什么库,它包含的库的哪个版本,它来自哪个repo。所有这些元数据都是gradle所需要的,并存储在gradle缓存中。Java生态系统至少承认,许多Java程序可以在一台机器上并行运行/开发,所有机器都不能运行您喜欢的linux风格,并且可能都需要相同库的不同版本。试图将相同的库版本强加给所有Java程序是行不通的。