I'm using Intellij IDEA 2017.2.4 and Gradle 4.0.1
I have few Spring Boot services. And I facing a problem to run them, they can fail while starting in a random way because of missing dependencies.
I have a parent project with build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org/m2/" }
mavenLocal()
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:$dependencyManagementPluginVersion")
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
group = '***'
version = '***'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
processResources {
filesMatching('**/*.yml') {
expand(project.properties)
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion")
mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
}
dependencies {
dependency "com.google.cloud:google-cloud-storage:$googleCloudStorageVersion"
...
dependency "org.junit.jupiter:junit-jupiter-api:$junitVersion"
}
}
}
And a child project build.gradle:
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
mavenLocal()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
...
testCompile('com.h2database:h2')
}
In some cases lombok dependency is missed, in other javax dependency. It shows that dependencies are not there.
But after I press Refresh All Gradle Projects and build once again it works.
Maybe someone encountered the same issue and have some solution for it?
It seems that you have problem with lombok dependency. First step is to ensure that lombok is added as your compile time dependency for example:
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.16.18'
}
Second step is to ensure that you have newest lombok plugin installed on your Intellij. It is very important when you are trying to compile your project inside IDE. Another thing that may help is setting to autoupdate dependencies in Intellij configuration.
Related
I am new to spring boot and gradle and trying to install the required dependencies, however the video i am watching is using an older version of gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE')
}
}
plugins {
id 'java'
id 'org.springframework.boot'
}
group 'com.teamtreehouse'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.1.214'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
I have tried using apply plugin but it does not seem to work. I am expecting to be able to run gradle build without any issues
Try add to settings.gradle:
pluginManagement {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
gradlePluginPortal()
}
}
and pass version to plugins section:
id 'org.springframework.boot' version '3.0.1'
I am trying to accomplish a Java Spring course at Coursera and downloaded the project with this gradle file.
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
maven { url "https://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
war {
baseName = 'gs-convert-jar-to-war'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://maven.springframework.org/milestone" }
flatDir {
dirs 'lib'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.data:spring-data-rest-webmvc")
compile("org.apache.httpcomponents:httpclient:4.5.6")
compile("org.hsqldb:hsqldb")
compile("com.google.guava:guava:17.0")
compile("org.apache.commons:commons-lang3:3.3.2")
compile("com.squareup.retrofit:retrofit:1.6.0")
compile("commons-io:commons-io:2.4")
compile("com.github.davidmarquis:fluent-interface-proxy:1.3.0")
compile(":mobilecloud.handin:1.0.0")
compile(":video.up.test:1.0.0")
compile(":autograder.handin:1.0.0")
compile(":autograder.spec:1.0.0")
testCompile("junit:junit")
}
Unfortunately, I have this error in IntelliJ Idea :
A problem occurred configuring root project 'mobile-cloud-asgn1'.
> Failed to notify project evaluation listener.
> org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
I am quite a newbie to Java and Gradle and never faced errors like this, so I have no idea how to fix it. Can anyone help me?
P.S. Repository with project template: https://github.com/juleswhite/mobile-cloud-asgn1
When attempting to use outside dependencies within a custom gradle plugin I'm building, I am not able to import or use them in any regard.
I've attempted to specify in both the build script and the normal dependencies closure my dependencies. I'm using Gradle 5.5 (wrapper script) and I am using the buildSrc method of writing a custom gradle plugin.
// Necessary if loading custom plugins
apply plugin: 'java-gradle-plugin'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.google.code.gson:gson:2.8.5'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
group 'com.foo'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gradlePlugin {
plugins {
greeterPlugin {
id = 'com.foo.dbcreation-plugin'
implementationClass = 'com.foo.dbcreation.DbCreation'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.8.5'
}
There are quite a few issues I see here.
buildscript does not control the dependencies for your plugin implementation.
Use the plugins {} DSL block to apply plugins. It is the preferred way: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block
Should be using implementation over compile since compile is deprecated as noted in https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
With that said, your Gradle file should be like:
plugins {
id 'java-gradle-plugin'
id 'eclipse'
id 'idea'
}
group 'com.foo'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gradlePlugin {
plugins {
greeterPlugin {
id = 'com.foo.dbcreation-plugin'
implementationClass = 'com.foo.dbcreation.DbCreation'
}
}
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
}
I figured out what my issue was. For projects being built using the buildSrc directory, you need to have the build.gradle file reside in that directory instead of the root project directory (where the build.gradle normally lives). I just converted the project to a normal gradle project and it works just fine.
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.