我们可以通过在 Gradle 中使用脚本插件来包含 buildscript 吗?

2024-02-10

我试图从外部 gradle 脚本中包含 buildscript,但不断出现一些错误。然后我就找到了这个论坛主题,不过是2012年讨论的。

https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016 https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016

从那以后有什么变化吗?

这是我的代码:

myPlugin.gradle

buildscript {
ext {
    springBootVersion = '1.3.5.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
}
}

subprojects {

apply plugin: 'java'
apply plugin: 'spring-boot' 

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    /*
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-starter-actuator")
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    */
}

}

构建.gradle

apply from: "../myProject/myPlugin.gradle"

抛出以下错误:

> Plugin with id 'spring-boot' not found.

为了使其工作,我改变了构建.gradle到这段代码:

buildscript {
ext {
    springBootVersion = '1.3.5.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
}
}

apply from: "../myProject/myPlugin.gradle"

效果很好。

谢谢...


不,没有变化。这仍然有效。我已经回答了question https://stackoverflow.com/questions/38081926/how-to-load-gradle-plugin-with-its-depenecies-into-build-gradle/最近与此主题相关的SO,所以没有任何改变。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我们可以通过在 Gradle 中使用脚本插件来包含 buildscript 吗? 的相关文章

随机推荐