Spring Boot OIDC Client Development Through VS Code Not working - 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

Related

Issue while setting up the spring boot with gradle

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.

OpenApi Not Working with Spring Boot Gradle Project

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.

How to best setup Multi Module Gradle Java Project to make a public Java API to a proprietary Codebase?

I am currently working on a Multi Module Gradle Java Project and want to expand the project to allow for a public Java API through which developers can add plugins to my core application (API), while my core code remains private (Core). The idea is similar to applications such as:
The Minecraft Plugin Frameworks (PaperMC), where the actual Minecraft code remains hidden but the respective API is publicly accessible.
Jenkins
I am trying to implement such a model for my own project with the following requirements:
Any code in Core must not be publicly accessible
When the API module is compiled it should not contain Core, but it has to be available to reference (So that I can ya know build the API)
Core should have access to API (So that I can integrate the API into the application)
The Core should have the API compiled into it so that any plugins that are injected can actually be correctly interpreted by the Core
If any of these requirements pose a fundamental flaw I can of course change the structure, the above is purely based on prior research.
Here is what I currently have, which is throwing a Circular dependency issue, because I am very clearly setting this up incorrectly.
Core:
plugins {
id 'java'
}
group 'com.awesomedude'
version '1.0.0-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jetbrains:annotations:22.0.0'
implementation 'commons-io:commons-io:2.11.0'
implementation project(':API')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
API:
plugins {
id 'java'
}
group 'com.awesomedude'
version '1.0.0-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
compileOnly project(':Core')
implementation 'org.jetbrains:annotations:22.0.0'
implementation 'commons-io:commons-io:2.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}

Using Eclipse NonNull annotations with multiple Gradle projects

We've been using the Eclipse #NonNull and #Nullable annotations in our code for a while.
We are now adding some Spring projects defined with Gradle to our system. These projects will share quite a bit of code with our standalone projects as well.
We are seeing a problem due the Eclipse annotations (being compile time checking) don't work when a Spring/Gradle project refers to the shared code via Gradle generated .jar file. Eclipse needs to have the source of the shared jar in order for the annotations to work. Attaching the source in the Eclipse project only works until you need to do a Gradle Refresh, as that rebuilds the eclipse .project and .classpath files.
It's also a problem that you have to explicitly rebuild the shared .jar each time you make a change to the shared code. It's not done automatically.
I haven't found a way to have the Spring/Gradle projects just use a 2nd source directory for the shared code, and not need to have the shared code as a generated .jar file.
Is there any good way to have shared code between multiple Gradle projects in Eclipse - without using an intermediate .jar file? (Or some other way to get the Eclipse annotations to work.)
Not really sure how to give a full example, as most of this is gradle and eclipse configuration.
Here are the Gradle config files: settings.gradle
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}
rootProject.name = 'App1-Account-Manager'
and build.gradle
plugins {
id 'org.springframework.boot' version '2.5.0-RC1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.efi'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.2'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
implementation files('lib/eflow/eFlowClientApi.jar',
'lib/eflow/eFlowCryptography.jar',
'lib/eflow/json-simple-1.1.1.jar',
'lib/eflow/commons-codec-1.4.jar',
'lib/eflow/commons-io-2.6.jar',
'lib/eflow/commons-lang-2.6.jar',
'lib/eflow/commons-logging-1.2.jar',
'../App1-Commons/build/libs/App1-Commons-0.0.1-SNAPSHOT.jar'
)
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.1.100'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.7'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
App1-Commons is the project of shared code that multiple other projects depend on. That's where a bunch of the #NonNull annotations are.
I can set the App1-Account-Manager project to depend on the App1-Commons project in eclipse - but as soon as you run a Gradle Refresh, it looses that connection.
I'd prefer to just have the source from App1-Commons included in the App1-Account-Manager project - but I don't see how to configure Gradle to do that with Eclipse projects.
I think I found the solution. I need to add a SourceSets block to the build.gradle file like this:
sourceSets {
main {
java {
srcDir 'src/main/java'
srcDir '../App1-Commons/src/main/java'
}
}
}
And remove the reference to the App1-Commons jar file.

How to use gradle 'api' dependency

I tried using the 'api' dependency keyword in my project , but I got this error saying it cannot find method api()
I tried it on a new project. this is the build.gradle file:
plugins {
id 'java'
}
group 'com.test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
api group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'
}
I am using gradle V4.9.
when I run gradle build I get this:
Could not find method api() for arguments [{group=com.google.guava, name=guava, version=27.0.1-jre}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
If I replace 'api' with 'implementation' everything works fine
What am I missing here?
Is there any setting that needs to be done?
The api configuration comes from the java-library plugin, in your build script you have just applied java plugin. See https://docs.gradle.org/current/userguide/java_library_plugin.html
The key difference between the standard Java plugin and the Java Library plugin is that the latter introduces the concept of an API exposed to consumers. A library is a Java component meant to be consumed by other components. It’s a very common use case in multi-project builds, but also as soon as you have external dependencies.
Just apply the java-library plugin (which extends java plugin) and it should work:
plugins {
id 'java-library'
}
For those using kotlin build scripts use the following:
plugins {
id("org.gradle.kotlin.kotlin-dsl")
}

Categories