I just want to set the default profile when I run gradleRun, but this is failing with cannot find method run()
I'm first wondering:
What does the buildscript do for me and how can I successfully use the spring-boot plugin
Could not find method bootRun() for arguments [build_74d21ufxy8p9tyrqny7v4pkut$_run_closure1#389a9e15] on root project 'core' of type org.gradle.api.Project.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE"
}
}
task local {
run { systemProperty "spring.profiles.active", "development" }
}
bootRun.mustRunAfter local
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
apply plugin: 'spring-boot'
group = 'com.remindful'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
Remove
task local {
run { systemProperty "spring.profiles.active", "development" }
}
bootRun.mustRunAfter local
Add
bootRun {
systemProperty "spring.profiles.active", "development"
}
To answer your questions about build script and spring-boot plugin, build script contains the tasks needed to build a project using gradle, this is simplistic description, check the documentation. Spring boot plugin
allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by spring-boot-dependencies
You can refere to the documentation here
Related
Spring boot makes it really easy to setup a simple app.
But it takes me longer to actually get a jar file which I can upload to a remote server.
I am using IntelliJ, no command line, and I use gradle. The application is running somehow out of Intellij. But where are the created files? Where is my jar from Bootjar?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
// add spring data repos
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql:42.2.4")
// REST interface
compile("org.springframework.boot:spring-boot-starter-data-rest")
// Security
compile("org.springframework.boot:spring-boot-starter-security")
}
Update: Added a picture of the project structure:
Update 2: Folder structure:
There will not be a jar created if you are just running this in your IDE. In order to do that, you need to run the gradle build (in your case) either from your IDE or the command line to get it to build it into a jar.
From the command line, go to your project directory and type this:
./gradlew build
This executes the gradle wrapper, which should download everything you need to run the build, and then executes the build.
You will then find your jar in build/lib
build/libs (if you've ran build to build the jar file)
In my project I'm using activeMQ artemis and Spring Boot. The application should be executed as an Apache Commons Daemon service. I'd like to use my custom launcher in this project.
The project has the following Gradle configuration:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7")
}
}
plugins {
id "org.sonarqube" version "2.6.1"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
ext {
commonsDaemonVersion = '1.1.0'
artemis = '2.4.0'
}
dependencies {
compile("org.apache.activemq:artemis-server:${artemis}")
compile("org.apache.activemq:artemis-core-client:${artemis}")
compile("commons-daemon:commons-daemon:${commonsDaemonVersion}")
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
}
Because I'm using activeMQ artemis, I can't use the Spring Boot Plugin's 1.5.x version, because its dependency management module downgrades apache activeMQ automatically to version 1.5.5.
Because this project has to be executed as an Apache Commons Daemon Service, I have to use my custom Spring Boot launcher, which makes it possible to have a static launcher and classloader. These two help me to stop the already running service.
I tried the following setup to add my custom launcher to the generated jar-file with the following setup. However, that isn't the right way to do it, because I have to add my launcher's class name manually to the manifest file.
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7")
}
}
plugins {
id "org.sonarqube" version "2.6.1"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
ext {
commonsDaemonVersion = '1.1.0'
artemis = '2.4.0'
}
configurations {
launcher
}
dependencies {
compile("org.apache.activemq:artemis-server:${artemis}")
compile("org.apache.activemq:artemis-core-client:${artemis}")
compile("commons-daemon:commons-daemon:${commonsDaemonVersion}")
launcher("com.mycompany.springboot.launcher:my-custom-launcher:0.1.0-RELEASE")
}
bootJar {
from project.configurations.launcher.each {
from(zipTree(it))
}
manifest {
attributes 'Main-Class': 'com.mycompany.springboot.launcher.CustomLauncher'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
}
In version 1.5.x I could just use the following option to add my launcher configuration:
springBoot {
layoutFactory = new com.mycompany.springboot.launcher.CustomLauncherFactory()
}
Is there any setup, which I could use to add my custom Launcher with Spring Boot Gradle Plugin 2.x or do I have to use any workarounds here?
I would suggest to look into using Spring Boot starter for Artemis spring-boot-starter-artemis. It should spin up embedded server without any friction.
I want to add the tomcat plugin to my gradle build, but the plugin cannot be found , gradle shows the error
Plugin with id 'com.bmuschko.tomcat' not found.
I followed the steps on the github page of this plugin, but it does not work.
In my project I have general build.gradle in this I am loading my project.gradle in this I defined the tomcat-plugin configuration.
build.gradle
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = 1.8
ext {
debug = false
}
apply from: 'project.gradle'
group = myGroup
version = myVersion + '-SNAPSHOT'
project.gradle
//https://github.com/bmuschko/gradle-tomcat-plugin
buildscript {
repositories {
jcenter();
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.2'
}
}
apply plugin: "com.bmuschko.tomcat"
apply plugin: "idea"
apply plugin: "project-report"
apply plugin: "war"
I can ensure that dependencies can be resolved from my machine, because other gradle projects work, so that it should not be a network issue, there is no proxy configuration etc.
You have to put buildscript{} into your main build.gradle. The buildscript process is outside the regular Gradle build. Same applies to plugins{} as well (since they are equivalent.)
So if you put
buildscript {
repositories {
jcenter();
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.2'
}
}
into your build.gradle, it would work.
[Update]
I have created a sample gradle project with the fix in it.
And the TravisCI build is here.
Or you may try using the plugin type:
apply plugin: com.bmuschko.gradle.tomcat.TomcatPlugin
instead of
apply plugin: "com.bmuschko.tomcat"
in your project.gradle file.
I am using Spring boot gradle plugin version 1.5.1 RELEASE as shown below. The build fails at webProject complaining about missing property 'mainClass' and works only when I run 'webProject:build'. Is this the expected usage?
Edit: Updated the build script and removed 'spring-boot' plugin from allProjects. Had to add 'bootRepackage' in web project as it was failing at this step - with the same error. Adding the 'bootRepackage' didn't help.
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '1.5.1.RELEASE'
}
defaultTasks 'clean', 'build'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
allprojects {
apply plugin: 'java'
//apply plugin: 'org.springframework.boot' -- Commented out based on the answer
repositories {
mavenLocal()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
//all dependencies
}
}
project('aProject') {
dependencies {
compile(project(':bProject'))
}
}
project('webProject') {
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
war {
baseName = 'webProject'
version = '1.0.0-SNAPSHOT'
}
dependencies {
compile(project(':aproject'))
compile(project(':bProject'))
compile 'org.springframework.boot:spring-boot-starter-tomcat'
}
springBoot {
mainClass = 'com.abc.SomeApplication'
}
bootRepackage{
enabled = false
mainClass = 'com.abc.SomeApplication'
}
}
Do not use Spring Boot gradle plugin in main project, only in webProject sub-module.
I have a similar problem in a multi module Spring boot project.
When compiling module A which doesn't have a main class. The main class is in a different module (module B).
I add a plugin in that module A's build.gradle.
apply plugin: 'application'
mainClassName = "module B.ITS_MAIN_CLASS"
Then it works.
I am attempting to work through the Spring Framework Restful Web Service creation tutorial(https://spring.io/guides/gs/rest-service/#scratch) using Gradle and IntelliJ. I have followed everything to the letter but being fairly new to Spring, IntelliJ, and Java in general I'm unsure how to go about further debugging my issue.
When I attempt to build my project I receive a few errors stating "Java: package org.springframework.web.bind.annotation does not exist." I'm guessing I'm missing a library reference but am unsure how to check and include it.
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.springframework:spring-web:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'hello_springtest'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
Just thought I'd add some additional information. I'm still seeing the errors and am unsure why but my project does report that the build was successful. When I attempt to make the project however that's when I receive the annotation does not exist error.
You have some dependency in your builds script, which seems to me redundant and causes Gradle to look up for additional dependencies.
Just remove this dependency from your buildscript dependencies
classpath("org.springframework:spring-web:${springBootVersion}")
I see no reason to use it within your buildscript.