The below is my build.gradle.
When I Bootrun, i get the error
Execution failed for task ':compileJava
invalid source release: 18
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.loginapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '18'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Since you're using IntelliJ, shared the screenshot and told us you alread checked the java version and I already got this error a few times here is my TODO I go through when I get this error:
Do what you showed us on the screenshot (Check Project Version and language level)
Do the same for Modules (Project Structure > Modules) Don't forget the Dependencies Tab there you can find the module SDK
Check Java Compiler (Settings > Build, Execution, Deployment > Compiler > Java Compiler) there you can see a Project bytecode version & Per-module bytecode version -> Check those
Hope this works :)
Related
I follow the instructions here for the latest spring.framework.boot plugin.
My build.gradle has
plugins {
id 'java-library'
id 'eclipse'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.6.2'
id 'org.springframework.boot.experimental.thin-launcher' version '1.0.23.RELEASE'
}
but gradle tasks have the error
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Could not find org.springframework.boot:spring-boot-dependencies:2.6.2.
UPDATE I neglected to add the final lines of the error description, which were in fact important to answer it.
Searched in the following locations:
- https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
- https://repo.spring.io/milestone/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
Here is a FULL file as an example: (this is the ROOT build.gradle) (If you code a monolith, you'll only have a root build.gradle, if you write multiple "gradle modules", you'll have a root and subproject build.gradle files) (if you have no idea what i'm talking about see link to docs.gradle.org at bottom)
(you can remove the dependencies, but i prefer to give a full working)
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-batch'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'com.h2database:h2'
implementation 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation 'org.springframework.integration:spring-integration-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
allprojects {
/* custom task to show dependencies. run "gradle printAllDependencies" from commandline. see https://stackoverflow.com/questions/44266687/how-to-print-out-all-dependencies-in-a-gradle-multi-project-build/54436979#54436979 */
task printAllDependencies(type: DependencyReportTask) {}
}
Alternatively, you can try a "gradle FLUSH"
Gradle FLUSH Cache
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
and alternatively, you can do an intelliJ "FLUSH"
(tested with IntelliJ version 2020.1 or later)
Close IntelliJ.
Delete the ".idea" folder off of the root folder.
Re OPEN the project.
Wait for Gradle imports and indices rebuild to complete
Try the IDE build again.
And the big hammer: "Invalidate IntelliJ caches". see https://www.jetbrains.com/help/rider/Cleaning_System_Cache.html and/or https://www.jetbrains.com/help/idea/invalidate-caches.html
If you're using Eclipse or NetBeans or Other, you'll have to find the "equivalent". The idea is that the IDE gets "confused".
BONUS
Multi Gradle Module :
https://docs.gradle.org/current/samples/sample_building_java_applications_multi_project.html
Thanks to #granadaCoder above, and after reinstalling Gradle to the latest version 7.3.3 the actual problem was that a 2nd repositories setting had crept into my build.gradle
repositories {
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
Which was exactly where the error said the dependencies were not found. I changed this to
repositories {
mavenCentral()
}
Things then started to work.
I've been put into the unfortunate situation where I need to deploy a gradle build on a time crunch when I have never worked with it before. I believe this worked previously but on an older version of gradle that I am unable to roll back to.
I'm running Gradle 7.1 and am receiving this error message:
Could not find method compile() for arguments [{group=org.slf4j,
name=slf4j-api, version=1.7.21}] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is the build.gradle file
allprojects {
ext.springVersion="4.2.0.RELEASE"
ext.slf4jVersion="1.7.10"
ext.springDataVersion = "1.8.0.RELEASE"
ext.hibernateVersion = "4.3.9.Final"
ext.springSecurityVersion = "4.2.0.RELEASE"
ext.springDataMongoDBVersion = "1.7.0.RELEASE"
ext.mysqlConnectorVersion = "5.1.13"
}
subprojects {
apply plugin: 'java'
apply plugin : 'eclipse-wtp'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.aet.accel'
version = '1.0.0'
repositories {
mavenLocal()
mavenCentral()
maven{url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"}
maven{url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/"}
}
dependencies {
// logging
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
compile "org.apache.logging.log4j:log4j-core:2.5"
compile "org.apache.logging.log4j:log4j-api:2.5"
}
}
Any sort of assistance is very much appreciated, as I am very out of my depth on this one. Thank you for taking a look.
compile has been deprecated, so for libraries use api or implementation
I have a Gradle project and I want to create a submodule but I am getting an FAILURE when building the project.
The error message is
Execution failed for task ':child-project:compileJava'
> Could not resolve all files for configuration 'child-project:compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter:.
Required by:
project :parent-project
This is the parent project build.gradle file:
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
allprojects {
apply plugin: 'java'
group = 'com.test'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
//local nexus
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
//other dependencies
}
This is the child project build.gradle:
plugins {
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
Please help, thanks in advance.
In order to be able to specify Spring Boot dependencies without versions, you need to apply the Spring Boot plugin to all modules. Right now you only have it in the parent project, but not the child.
Because applying the plugin will also, by default, disable the normal jar task can create a bootJar instead, you need to change this for libraries:
// Child build file
plugins {
// Note that there are no versions on the plugins in the child project as this is defined by the ones in the parent
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
}
Alternatively, you could also scrap the io.spring.dependency-management plugin (and the org.springframework.boot plugin in the child project), and instead import the Spring Boot BOM as a platform:
// Child build file (alternative)
dependencies {
// Use 'platform' for making the versions in the BOM a recommendation only, and 'enforcedPlatform' for making them a requirement.
// Note that you need the version of the BOM, so I recommend putting it in a property.
implementation enforcedPlatform("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
// Here you can leave out the version
implementation 'org.springframework.boot:spring-boot-starter'
}
I usually go for the latter alternative as this allows me to use normal Gradle semantics. But it is mostly just preference.
(And just a small note to your build script: the compile configuration is deprecated. It is used in the line compile 'org.springframework.boot:spring-boot-starter'. You probably just copy/pasted it from somewhere, but you should replace it with implementation.)
Gradle command throwing below Exception:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/abel/Desktop/work/gundam/build.gradle' line: 2
What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.1.6.RELEASE'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.6.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 5s
Configuration:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
You should upgrade the gradle version and currently upgrade to Gradle 5.5.1 is ok,
and you need to set your idea to the current update gradle version
https://plugins.gradle.org/plugin/org.springframework.boot
It is because of network problem, when I change the vpn , it started working
Following is my build.gradle file. My project compiles locally (IntelliJ-IDEA is my IDE), but when I push it to GitHub, the travis-ci build fails. My gradle version is gradle-5.2.
apply plugin: "java"
apply plugin: 'jacoco'
sourceCompatibility = 1.8
version = "1.0"
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.2'
compileOnly 'org.projectlombok:lombok:1.18.2'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.2'
testCompileOnly 'org.projectlombok:lombok:1.18.2'
}
FAILURE: Build failed with an exception.
Where: Build file '/home/travis/build/XXX/PROJECT/build.gradle' line: 33
What went wrong: A problem occurred evaluating root project 'PROJECT'.
Could not find method annotationProcessor() for arguments [org.projectlombok:lombok:1.18.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
The annotationProcessor in build.gradle seems not to be parsed, I'm not sure what the underlying issue is. Any help would be appreciated. Thanks.
As #M.Ricciuti said, the annotationProcessor is available from gradle versions 4.6 and later. So what we should do is just confirm that gradle's version >= 4.6. We'd be better off using the Wrapper.Thanks, that's all.
A ery easy way to update the gradle version of your project in intellij is to go to inside your project, gradle, wrapper, gradle-wrapper.properties and update the version in the line below:
disributionUrl=https://services.gradle.org/distributions/gradle-4.6-bin.zip