英文:
Why am I getting "Could not get unknown property 'BootRun' for root project" when I have the Spring boot gradle plugin installed
问题
尝试创建一个只在本地运行时使用 h2 的项目。根据一些答案编写了以下内容...
plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '3.1.1-SNAPSHOT'
id 'io.spring.dependency-management' version '1.1.0'
}
...
configurations {
compileOnly {
extendsFrom annotationProcessor
}
localDatabase
}
...
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
localDatabase 'com.h2database:h2'
}
...
task bootRunLocal(type: BootRun, group: ApplicationPlugin.APPLICATION_GROUP, dependsOn: classes) {
mainClass = 'com.cbusha.be.BackendApplication'
classpath = sourceSets.main.runtimeClasspath + configurations.localDatabase
systemProperty "spring.profiles.active", "local"
}
但是当我运行 gradle bootRunLocal
时,出现以下错误:
A problem occurred evaluating root project 'backend'.
> Could not get unknown property 'BootRun' for root project 'backend' of type org.gradle.api.Project.
如何使自定义任务工作?
英文:
Trying to create a project that only uses h2 when running locally. Came up with this off of some answers...
plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '3.1.1-SNAPSHOT'
id 'io.spring.dependency-management' version '1.1.0'
}
...
configurations {
compileOnly {
extendsFrom annotationProcessor
}
localDatabase
}
...
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
localDatabase 'com.h2database:h2'
}
...
task bootRunLocal(type: BootRun, group: ApplicationPlugin.APPLICATION_GROUP, dependsOn: classes) {
mainClass = 'com.cbusha.be.BackendApplication'
classpath = sourceSets.main.runtimeClasspath + configurations.localDatabase
systemProperty "spring.profiles.active", "local"
}
But when I run gradle bootRunLocal
I get
A problem occurred evaluating root project 'backend'.
> Could not get unknown property 'BootRun' for root project 'backend' of type org.gradle.api.Project.
How do I get the custom task to work?
答案1
得分: 2
Import the class. Add:
import org.springframework.boot.gradle.tasks.run.BootRun
At the top of your buildscript.
英文:
Import the class. Add:
import org.springframework.boot.gradle.tasks.run.BootRun
At the top of your buildscript.
答案2
得分: 0
另一个似乎有效但我在得到上面的答案后替换掉的答案是...
task bootRunLocal(type: JavaExec, group: 'Application') {
classpath = sourceSets.main.runtimeClasspath + configurations.localDatabase
mainClass = 'com.cbusha.be.BackendApplication' // 用你的Spring Boot应用程序的主类替换
args = ['--spring.profiles.active=local,test']
}
英文:
Another answer that seemed to work but I replaced when I got the above answer was...
task bootRunLocal(type: JavaExec, group: 'Application') {
classpath = sourceSets.main.runtimeClasspath + configurations.localDatabase
mainClass = 'com.cbusha.be.BackendApplication' // Replace with the main class of your Spring Boot application
args = ['--spring.profiles.active=local,test']
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论