我正在尝试在我的gradle项目中使用Spring启动。但是当我尝试clean build
时,它会给出以下错误(只有相关的堆栈跟踪):
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'spring-boot']
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:117)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:131)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:37)
at org.gradle.api.Project$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
at org.gradle.api.Script$apply.callCurrent(Unknown Source)
at build_2o7juvjo3110jmss6k1iqcfrir.run(/Users/AlmasBarday/bos-api/build.gradle:13)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 57 more
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'spring-boot' not found.
at org.gradle.api.internal.plugins.DefaultPluginRegistry.getTypeForId(DefaultPluginRegistry.java:91)
at org.gradle.api.internal.plugins.DefaultPluginContainer.getTypeForId(DefaultPluginContainer.java:183)
at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:103)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:115)
我的build.gradle有以下内容:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'spring-boot'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
compile 'com.qas:proweb:1.0.0'
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
testCompile 'junit:junit:4.11'
}
我搜索了互联网并尝试了解决类似问题的解决方案,但似乎没有任何效果。此外,我能够毫无问题地构建另一个gradle-springboot项目。
任何帮助表示感谢。
答案 0 :(得分:2)
您已经忘记通过添加它的依赖项部分来配置您的buildscript。你可以把它添加到你的build.script:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
在这里,您要配置您的buildscript依赖项,以便Gradle可以应用该插件。但这并不意味着您可以删除源代码的依赖关系。他们仍然有用,就像你已经拥有的那样:
dependencies {
...
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
}
答案 1 :(得分:0)
plugins { id "org.springframework.boot" version "2.0.1.RELEASE" }
上面的脚本也应该添加到build.gradle
的顶层,以使其起作用。