I am trying to setting up a Spring boot gradle project in intelliJ. If I am trying with reload button on the gradle pane, it's giving me error for setting.gradle
but setting.gradle file is already there is the root directory.
When I tried ./gradlew clean build on terminal getting the below error:
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
}
group 'com'
version '1.0'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
java {
sourceCompatibility = JavaVersion.toVersion('11')
targetCompatibility = JavaVersion.toVersion('11')
}
I tried but couldn't figure out what I am missing. Please suggest.
Update: I tried to delete gradle installation from the system and executed one another application which was working fine earlier but not even after downloading the gradle version, getting the same error as mentioned above.
I tried Maven project with spring initializr and it successfully build so It seems to be an issue regarding gradle setup on my machine but not sure what to check.**
Regards
Not Sure why error message was not that clear. It was related to certificate issue. I added some organization specific certificate in java cacerts keystore and it resolved the gradle issue with plugin download.
Thanks to All who tried to help.
Related
I am trying to add OpenApi to my Spring Boot Gradle project. I've added the OpenAPI plugin to my build.gradle file, but when I start my app, none of the URLs that are supposed to make documentation seem to get generated.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.1-SNAPSHOT'
id 'io.spring.dependency-management' version '1.1.0'
id "org.springdoc.openapi-gradle-plugin" version "1.6.0"
}
group = 'com.sampleproject'
sourceCompatibility = '17'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
application.properties
server.servlet.context-path=/sample-service
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui-custom.html
I have tried building and running my project with:
./gradlew clean build followed by java -jar build/libs/name-of-jar-file.jar
./gradlew clean generateOpenApiDocs
Links that I've been using:
https://springdoc.org/v2/#gradle-plugin
https://github.com/springdoc/springdoc-openapi-gradle-plugin
Both links say to add the plugin, which I did. When my app is running, I try going to http://localhost:8080/sample-service/api-docs and http://localhost:8080/sample-service/swagger-ui-custom.html, and both give me the standard spring white label error page.
I have two controller classes in my application, and all endpoints work fine when my app is running.
What am I missing or doing wrong in order to get OpenAPI to work with my Spring Boot Gradle application?
In order to enable swagger UI, you will need to add the plugin of
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.14'
Adding this to build.gradle dependencies will solve your problem. I hope this helps.
I am currently running the latest IntelliJ and I am trying to use SparkJava Webserver for a Gradle project I'm writing.
When I do compile and run with gradle everything works fine, however I am getting an error in
import static spark.Spark.*;
Where IntelliJ cannot resolve the symbol spark, even though I obviously have the correct dependency set in my build.gradle:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'mysql:mysql-connector-java:8.0.27'
implementation "com.sparkjava:spark-core:2.9.3"
implementation "org.slf4j:slf4j-simple:1.7.9"
}
test {
useJUnitPlatform()
}
Is there any way to circumvent this?
Many thanks in advance.
I got it:
In IntelliJ, under View -> Tool Windows -> Gradle there's an option to refresh everything Gradle related at the following button:
Using this refreshes the cache and yields the correctly imported dependency.
I want to create an executable Jar for Spring Boot using gradle in an offline environment.
There is an error.
Please tell me the solution.
■cmd
C: / ~ / ~ / demo gradlew bootJar --offline --stacktrace
FAILURE: Build failed with an excetion.
What went wrong:
Task 'bootJar' not found in root project 'demo'.
Exception is:
org.gradle.execution. TaskSelectionException: Task 'bootJar' not found in root project 'demo'.
......
■build.gradle
plugins {
// id 'org.springframework.boot' version '2.4.2'
// id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
■gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
■version
SpringBoot:2.4.2
gradle:6.6.1
The bootJar task comes from the Spring Boot Gradle plugin (org.springframework.boot). You've removed the plugin from the project therefore the bootJar task never gets created.
Gradle is smart enough to cache various parts of the build including dependencies and plugins. However, since you are getting that error, the Spring Boot plugin is not cached therefore you must go online temporarily in order for the plugin to be downloaded and cached.
If you're not able to temporarily go online, then for the bootJar task specifically, you must reimplement yourself in your project: https://github.com/spring-projects/spring-boot/blob/2.4.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
So, I am utilizing this java OIDC client.
I can get it to run with their suggested ./gradlew bootRun.
However, I want to debug the source code in VSCode, and cannot seem to do that.
I get this error in VSCode:
I did not modify this build.gradle at all (except for the java version used). Here is what it looks like:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'io.curity.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
Do I need to have some extra configuration somewhere since it's development environment?
Looking at the Gradle Documentation it seems like the build.gradle should be configured correctly.
Is there a special Gradle command I need to run when working with local development, as opposed to "prodcution" environment.
I am running the application in Debug by simply running "Debug" in VSCode on the main function
Doing that gives me this error though:
I can "Proceed", but that doesn't seem to correctly run the application as I am not able to successfully navigate to http://localhost:8080 to see the main index page of the application.
This is the output in my terminal when just proceeding
I should note that I'm new to Java and Gradle, in general. I have C#/.NET bakcground.
Thanks
This question already has answers here:
How to add a Maven project as a Gradle dependency?
(3 answers)
Closed 2 years ago.
I have created dependency jar using maven project but now i have to add this maven dependency into my gradle project.
Depencency available in my .m2 directory
Am getting the below error from intellij .
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Cannot convert URL 'com.example.auth.security:common:0.0.1-SNAPSHOT.jar' to a file.
Please find my build.gradle file
plugins {
id 'org.springframework.boot' version '2.1.16.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.example.auth'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation files('com.example.auth.security:common:0.0.1-SNAPSHOT.jar') --> getting error on this line.
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
compileOnly 'org.projectlombok:lombok'
implementation('io.jsonwebtoken:jjwt:0.9.1')
}
Update 1
A problem occurred evaluating root project 'auth-center'.
> Supplied String module notation '0.0.1-SNAPSHOT' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'.
You will need to add a local maven repository like this
repositories {
maven { url new File(pathToYourM2Directory).toURI().toURL() }
}
Additionally the declaration of the dependency is not correct. It should be
dependencies {
implementation group: 'com.example.auth.security', name: 'common', version '0.0.1-SNAPSHOT'
}
You can as well fix the files dependency. However using a local maven repo is more sustainable as by resolving artifacts this way it is transparent for the build process if an artifact is resolved locally or remote.
Can't comment since I don't have sufficient reputation. I believe you shouldn't be trying to add the maven dependency to the gradle project. Instead, host the maven dependency elsewhere and configure gradle to pull dependencies from there. For reference, you can take a look at this answer
How to add a Maven project as a Gradle dependency?
This is another way to import your custom java library(.jar).
What you need to do is that first, make a folder wherever you want under your project, in my case /src/lib, and put JAR file into that folder. Then, write down the below code into your Gradle file.
dependencies {
//Library Auto Implement
//Replace with your folder URI
implementation(fileTree("./src/lib"))
}
Then Gradle will implement your JAR files from that folder, and you are ready to go.