IntelliJ Idea can not run spring boot with gradle - spring-boot

I built a spring boot project .It used gradle 4.9,JDK 1.8 and idea .but I can't run the application
Build.gradle
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management' group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8 repositories
{
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/boot/SpringApplication
Thanks for your help!

Related

Spring Data ElasticSearch override version

i upgraded springboot version 2.6.6 from 2.5.7.
and i'm using spring-data-elasticsearch.
i want to keep spring-data-elasticsearch version ( i'm using 4.2.7 )
so, i configured this.
implementation("org.springframework.data:spring-data-elasticsearch:4.2.7") --> it doesn't work
but my library still using version 4.3.3.
how can i overriding downgrade elastic version?
it's fine to upgrading a version
implementation("org.springframework.data:spring-data-elasticsearch:4.3.4") --> it works
here is my gradle settings
root
buildscript {
ext {
spring_boot_version = '2.6.6'
spring_data_elasticsearch_version = '4.2.7'
query_dsl_version = '4.3.1'
lombok_version = '1.18.12'
poi_version = '4.1.2'
}
}
plugins {
id 'java-library'
id 'org.springframework.boot' version "${spring_boot_version}"
}
subprojects {
version = '1.0.0-SNAPSHOT'
apply plugin: 'idea'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: "org.springframework.boot"
apply plugin: 'groovy'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenLocal()
mavenCentral()
}
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
implementation platform("org.springframework.boot:spring-boot-dependencies:${spring_boot_version}")
annotationProcessor platform("org.springframework.boot:spring-boot-dependencies:${spring_boot_version}")
testAnnotationProcessor platform("org.springframework.boot:spring-boot-dependencies:${spring_boot_version}")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
annotationProcessor("com.querydsl:querydsl-apt:${query_dsl_version}:jpa")
annotationProcessor("com.querydsl:querydsl-apt:${query_dsl_version}:general")
annotationProcessor("org.projectlombok:lombok")
annotationProcessor('javax.persistence:javax.persistence-api:2.2')
annotationProcessor('javax.annotation:javax.annotation-api:1.3.2')
testAnnotationProcessor("org.projectlombok:lombok")
testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0')
testImplementation('org.spockframework:spock-spring:2.0-M4-groovy-3.0')
}
compileJava.dependsOn(processResources)
}
submodule
dependencies {
implementation("org.springframework.data:spring-data-elasticsearch:4.2.7")
}

intellij Gradle Sync Error : "Could not resolve all artifacts for configuration ':classpath'."

This is my build.gradle
buildscript {
ext {
springBootVersion = '2.1.7.REALEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web:')
testCompile('org.springframework.boot:spring-boot-starter-test:')
}
and this is the Sync ErrorMessage
Could not resolve all artifacts for configuration ':classpath'.
Could not find org.springframework.boot:spring-boot-gradle-plugin:2.1.7.REALEASE.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/2.1.7.REALEASE/spring-boot-gradle-plugin-2.1.7.REALEASE.pom
- https://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/2.1.7.REALEASE/spring-boot-gradle-plugin-2.1.7.REALEASE.pom
Required by:
project :
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
There are clearly declared repositories like mavenCentral() and jcnenter(), but can't build it.
I was told jcenter no longer be serviced, so I changed dependencies and deleted jcenter().
This build is successfully worked.
buildscript {
ext{
springBootVersion = '2.1.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
test {
useJUnitPlatform()
}

unable to run the springboot jar from command line

My requirement is to build a spring boot jar in standalone tomcat executable.I am not able to run the jar from command line.
I am using gradle
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':testProject')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
jar {
manifest {
attributes 'Implementation-Title': 'SpringAppApplication',
'Implementation-Version': version
}
}
running java -jar target/SpringAppApplication-0.0.1-SNAPSHOT.jar
I get error Invalid or corrupt jarfile SpringApp-0.0.1-SNAPSHOT.jar
.Tried giving the complete path also.

Gradle build doesn't add version to package

I'm creating a REST microservice using Spring Boot 2.0.0.M7 with Gradle 4.2.
When I build from Eclipse or run from console ./gradlew build, the produced package in build/libs is named $app.jar instead of $app-$version.jar.
What am I missing? my build.gradle is the same as the Spring Boot Docker GS guide, and this problem prevent docker image to be built because the jar can't be found.
Here is my build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.0.M7'
springCloudVersion = 'Finchley.M5'
gradleDockerVersion = '0.13.0'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.palantir.gradle.docker:gradle-docker:${gradleDockerVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'networks'
version = '0.9'
}
group = 'test'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'org.springframework.boot:spring-boot-starter-json'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
runtime 'org.springframework.boot:spring-boot-devtools'
runtime 'org.postgresql:postgresql'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit'
}
docker {
name "${project.group}/${jar.baseName}"
files jar.archivePath
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
The version should be specified outside jar:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = "0.9"
jar {
baseName = 'networks'
}

spring-boot gradle plugin can't be found

I have a separate gradle script that is just adding spring-boot plugin. It looks like this:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url 'http://repo.spring.io/libs-release' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE'
}
}
apply plugin: 'spring-boot'
Then, in another project, it is referenced like this:
apply from: '../../food-orders-online-main/spring-boot.gradle'
When I run build task I'm getting the following error:
A problem occurred evaluating script.
> Failed to apply plugin [id 'spring-boot']
> Plugin with id 'spring-boot' not found.
Someone knows what I'm doing wrong?
Applying a plugin by plugin id is not supported in script plugins. You must use the plugin's fully qualified class name.
apply plugin: org.springframework.boot.gradle.plugin.SpringBootPlugin
See this thread for more information.
UPDATE: Updating plugin class name.
These are the Plugins that I am using on spring boot 2.0.1
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
My complete vanilla gradle file here (Spring boot 2.0.5)
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
OR
there is an even better option, go to the spring starter (spring boot template generating tool) start.spring.io And generate a template project from there, and build step-by-step from there.
This code works for me
plugins{
id 'org.springframework.boot' version '2.0.3.RELEASE'
}
Add:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.4.RELEASE"
}}
Change:
apply plugin: 'spring-boot'
to:
apply plugin: "org.springframework.boot"
Starting from SpringBoot 1.4.0.RELEASE the plugin package has been slightly changed.
apply plugin: org.springframework.boot.gradle.plugin.SpringBootPlugin
Check your syntax and where your parentheses close } I had the same issue and it turned out my repositories { didnt contain } at the end
Got a similar exception
Caused by: org.gradle.internal.resolve.ArtifactNotFoundException: Could not find spring-boot-gradle-plugin-3.0.0-SNAPSHOT.jar (org.springframework.boot:spring-boot-gradle-plugin:3.0.0-SNAPSHOT:20220216.230329-214)
Running the gradle build with --refresh-dependencies fixed it
Below code works for me:-
buildscript {
ext { springBootVersion = '2.0.5.RELEASE'}
repositories { mavenCentral() }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-
starter-web', version: '2.0.5.RELEASE'
}
After proxy setting ( What is the proxy IP in your organization), I have added following code in build.gradle file. The problem has gone.
sourceSets {
main {
output.setResourcesDir(java.outputDir)
}
}
As of now July first 2020, this is how I was able to configure it, and it worked! Hopefully, this can help anyone facing this problem.
Note: Pay attention to the versions
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:2.2.8.RELEASE')
}
}
plugins {
id 'org.springframework.boot' version '2.2.8.RELEASE'
id 'java'
}
group 'org.capfer'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile('org.springframework.boot:spring-boot-starter-web:2.2.8.RELEASE')
}
could it be, that you don't have a #SpringBootApplication with a main(String[] main) on your classpath ??

Resources