在 init.gradle 脚本中应用插件配置
Apply plugin configuration in init.gradle script
我想为我的所有项目在本地安装一些包,例如依赖分析。但我需要实际配置插件 - 也在初始化脚本中。
initscript {
repositories {
jcenter()
}
dependencies {
classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
}
}
allprojects {
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
}
这个初始化脚本工作正常并应用了插件,但不幸的是,默认设置是插件无法构建。我只想记录一个警告。
为此我需要添加配置:
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
但是当我尝试将它添加到 init.gradle 文件中时:
initscript {
repositories {
jcenter()
}
dependencies {
classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
}
}
allprojects {
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
}
我得到一个错误:
FAILURE: Build failed with an exception.
* Where:
Initialization script '/Users/<my-user>/.gradle/init.gradle' line: 13
* What went wrong:
Could not find method analyzeClassesDependencies() for arguments [init_2y9p9if69e8553k9fsvzz4a28$_run_closure1$_closure2@3e17c37a] on root project 'my-project' of type org.gradle.api.Project.
有人知道如何应用插件配置吗?
我尝试了 gradle forum 但没有得到任何答案,所以我希望在这里得到更多帮助 :)
AnalyzeDependenciesPlugin
将根据您的项目应用的插件添加不同的任务。例如 analyzeClassesDependencies
和 analyzeTestClassesDependencies
将仅在应用 java
插件时声明(请参阅此处如何实现此插件:https://github.com/wfhartford/gradle-dependency-analyze/blob/master/src/main/groovy/ca/cutterslade/gradle/analyze/AnalyzeDependenciesPlugin.groovy)
因此,在 allprojects
配置闭包中应用 AnalyzeDependenciesPlugin
之前,您只需要应用 java
插件:
allprojects {
apply plugin: "java" // <= apply Java plugin here
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
}
我想为我的所有项目在本地安装一些包,例如依赖分析。但我需要实际配置插件 - 也在初始化脚本中。
initscript {
repositories {
jcenter()
}
dependencies {
classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
}
}
allprojects {
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
}
这个初始化脚本工作正常并应用了插件,但不幸的是,默认设置是插件无法构建。我只想记录一个警告。
为此我需要添加配置:
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
但是当我尝试将它添加到 init.gradle 文件中时:
initscript {
repositories {
jcenter()
}
dependencies {
classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
}
}
allprojects {
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
}
我得到一个错误:
FAILURE: Build failed with an exception.
* Where:
Initialization script '/Users/<my-user>/.gradle/init.gradle' line: 13
* What went wrong:
Could not find method analyzeClassesDependencies() for arguments [init_2y9p9if69e8553k9fsvzz4a28$_run_closure1$_closure2@3e17c37a] on root project 'my-project' of type org.gradle.api.Project.
有人知道如何应用插件配置吗? 我尝试了 gradle forum 但没有得到任何答案,所以我希望在这里得到更多帮助 :)
AnalyzeDependenciesPlugin
将根据您的项目应用的插件添加不同的任务。例如 analyzeClassesDependencies
和 analyzeTestClassesDependencies
将仅在应用 java
插件时声明(请参阅此处如何实现此插件:https://github.com/wfhartford/gradle-dependency-analyze/blob/master/src/main/groovy/ca/cutterslade/gradle/analyze/AnalyzeDependenciesPlugin.groovy)
因此,在 allprojects
配置闭包中应用 AnalyzeDependenciesPlugin
之前,您只需要应用 java
插件:
allprojects {
apply plugin: "java" // <= apply Java plugin here
apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
analyzeClassesDependencies {
justWarn = true
}
analyzeTestClassesDependencies {
justWarn = true
}
}