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

我们可以在Gradle中使用脚本插件来包含buildscript吗?,gradle,gradle-plugin,Gradle,Gradle Plugin,我试图从一个外部gradle脚本中包含buildscript,但不断地得到一些错误。然后我找到了这个论坛主题,但它在2012年被讨论过 从那以后有什么变化吗 这是我的密码: myPlugin.gradle buildscript { ext { springBootVersion = '1.3.5.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframewor

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

从那以后有什么变化吗

这是我的密码:

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

}
apply from: "../myProject/myPlugin.gradle"
build.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') 
    */
}

}
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"
这很好用


谢谢……

不,没有变化。这仍然有效。我最近回答了与这个话题相关的问题,所以没有任何变化

从您对链接问题的回答中,我可以看出,您在外部脚本中包含了“buildscript”闭包。这真的有效吗?实际上,我的问题和链接的问题是一样的。也许我应该添加一些代码。是的,它很有效。请添加显示简化问题的代码。我添加了代码。但后来我找到了这个链接,它显示了如何将buildscript作为外部脚本包括在内: