【问题标题】:Can we include buildscript by using script plugins in Gradle?我们可以通过在 Gradle 中使用脚本插件来包含 buildscript 吗?
【发布时间】:2016-07-13 20:01:43
【问题描述】:

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

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') 
    */
}

}

build.gradle

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

抛出以下错误:

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

为了使其正常工作,我将 build.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"

效果很好。

谢谢...

【问题讨论】:

    标签: gradle gradle-plugin


    【解决方案1】:

    不,没有变化。这仍然有效。我最近在 SO 上回复了与此主题相关的question,所以没有任何改变。

    【讨论】:

    • 据我从您对链接问题的回答中可以看出,您在外部脚本中包含了“buildscript”闭包。这真的有效吗?实际上我的问题与链接的问题相同。也许我应该添加一些代码。
    • 是的,它有效。请添加显示简化问题的代码。
    • 我添加了代码。但后来我找到了这个链接,它显示了如何将 buildscript 包含为外部脚本:discuss.gradle.org/t/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2014-05-13
    • 2017-06-26
    • 2013-11-07
    相关资源
    最近更新 更多