I'm working on small spring boot project using gradle and intellij idea.
After I created a project and restarted intellij idea build.gradle file contents became gray.
But despite this it runs well and I don't get any compilation errors.
Intellij Idea Ultimate version 2019.3.1, java 8, gradle 6.0.1, spring boot 2.1.7
The code of build.gradle is below.
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenCentral()
}
dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I've tried to restart Idea again. It didn't help. Then I've tried to use an older version of gradle but everything remains as before.
Related
The error gets thrown for org/apache/commons/compress/archivers/tar/TarArchiveInputStream as seen here.
I have referenced this library in eclipse (as seen here)
The dependency has also been specified in build.gradle. The contents of the gradle file:
plugins {
id 'org.spongepowered.plugin' version '0.9.0'
}
group = pluginGroup
version = pluginVersion
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
dependencies {
compileOnly 'org.spongepowered:spongeapi:7.2.0'
annotationProcessor 'org.spongepowered:spongeapi:7.2.0'
compile 'org.apache.commons:commons-compress:1.21'
}
sponge.plugin.id = pluginId
Eclipse also does not flag any errors. Lines of code such as tarInput.getNextTarEntry() appear in the correct colour with no red underlining, and eclipse even autocompletes the names of methods found in commons-compress.
Given eclipse seems to be working correctly with the dependency, and given that running ./gradlew build leads to a successful build, I am therefore at a loss for why I am getting the java.lang.NoClassDefFoundError error.
#nitind helped. I focused upon runtime and found the problem was to do with my build.gradle file (even though the build was successful!). I changed it to this and the error has vanished:
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.spongepowered.plugin' version '0.9.0'
}
apply plugin: 'java'
group = pluginGroup
version = pluginVersion
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
dependencies {
compileOnly 'org.spongepowered:spongeapi:7.2.0'
annotationProcessor 'org.spongepowered:spongeapi:7.2.0'
compile 'org.apache.commons:commons-compress:1.21'
}
jar {
from configurations.compile.collect { zipTree it }
}
sponge.plugin.id = pluginId
I am using spring-boot and gradle. I want to use latest selenium version, however half of compile dependencies, including drivers, are somehow 3.14 version. I tried invalidating caches, ./gradlew clean build, ./gradlew build --refresh-dependencies, but it doesn't help. My older project has the same dependencies (but no spring-boot) and I this issue is not present.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'xxx.xxxxxx'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
// https://mvnrepository.com/artifact/org.testng/testng
testImplementation 'org.testng:testng:7.5'
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
testImplementation 'io.rest-assured:rest-assured:4.5.1'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
implementation 'io.github.bonigarcia:webdrivermanager:5.1.1'
// https://mvnrepository.com/artifact/com.github.javafaker/javafaker
implementation 'com.github.javafaker:javafaker:1.0.2'
// https://mvnrepository.com/artifact/org.assertj/assertj-core
testImplementation 'org.assertj:assertj-core:3.22.0'
}
test {
useTestNG()
testLogging {
exceptionFormat(TestExceptionFormat.FULL)
}
systemProperties(System.getProperties())
}
Spring Boot manages the versions for Selenium, so in your case you only specified the version for selenium-java, all other versions were managed by Spring Boot. To properly update all Selenium dependencies, you have to override the property for the Selenium version:
ext['selenium.version'] = '4.1.4'
and remove the version from the selenium-java entry:
implementation 'org.seleniumhq.selenium:selenium-java'
You can find all available properties for libraries managed by Spring Boot in the documentation: https://docs.spring.io/spring-boot/docs/2.6.7/reference/htmlsingle/#appendix.dependency-versions.properties
Helo! Sorry for my English, but it's not my native language. I'm trying to make a project to practice webflux and I can't get Swagger to work. I did a good search on StackOverflow and Google and couldn't find a solution. I also tried looking in the SpringFox documentation, but maybe I didn't quite understand. I decided to ask my first question to StackOverflow:
What is missing from my project settings to make Swagger work?
build.gradle root:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE"
}
}
plugins {
id "application"
id 'java'
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "io.freefair.lombok" version "5.1.0"
}
dependencies {
compile project(":contract")
}
mainClassName = 'com.pocwebflux.PocWebfluxApplication'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
jcenter()
}
allprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.freefair.lombok'
apply plugin: 'org.springframework.boot'
group = 'com.example'
version = "1.0.0-SNAPSHOT"
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation "io.springfox:springfox-boot-starter:3.0.0"
compile 'io.springfox:springfox-swagger-ui:3.0.0'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
}
test {
useJUnitPlatform()
}
}
build.gradle contract layer:
dependencies {
implementation project(':impl')
}
impl layer: nothing
I still don't have anything implementing just a controller with a test endpoint, just to see if the swagger was working:
ClientController
I created this class following the documentation, but I'm not sure where to use it:
SwaggerUiWebFluxConfigurer
What would be missing from the settings?
Could someone please clarify my question? Thank you very much.
I forgot to say that the build project normally and the service goes up and returns 200 in Postman.
After a series of tries and researches, I found that my problem was with Intellij. I had a cash problem, and I wasn't downloading the dependencies. I did a ./gradlew clean, deleted all springfox and swagger libraries. I went to the root of the project and deleted the ".idea" folder. I downloaded the dependencies again and it includes this:
implementation group: 'org.springframework.plugin', name: 'spring-plugin-core', version: '2.0.0.RELEASE'
Done!
Now it's working.
I am trying to test setting up a minimal project, building and exporting it as a jar, and using that project as a dependency in another. I am using Spring for this. I have two projects, makeajar and useajar. In makeajar, I set up a simple project with a Java class called Dinner. I want to import the jar for this project as part of the library in useajar, and from useajar instantiate a Dinner object.
However, the issue I'm getting is that I can't import the Dinner class. When I do, the import shows red:
Is there something I'm doing wrong in this process?
Things I've already tried:
Invalidating caches and restarting
Creating a fresh project
Adding makeajar as a module dependency (note: This was already there, and also appeared in the Project Structure -> Libraries)
How I produce the jar file from makeajar:
Go to project root directory and run ./gradlew build
Things I'm noticing:
Although makeajar appears in my module dependencies and libraries, it does not appear in the "External Libraries" folder in the useajar project.
I can gradle refresh fine, and if I comment out the attempts to import the Dinner object, I build.
I can easily get various popular dependencies (i.e. Jackson, guava) from MavenCentral and use these right out of the box. The issue is only occurring with my makeajar dependency.
makeajar build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.12.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.makingajar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
useajar build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.12.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'idea'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
apply plugin: 'idea'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
mavenLocal {
flatDir {
dirs projectDir.toString() + '/libs'
}
}
}
allprojects {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'com.makingajar:makeajar2:0.0.1-SNAPSHOT'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.3'
}
}
test {
useJUnitPlatform()
}
IntelliJ version 2020.1.4
Gradle version 6.6.1
I am trying to build simple hello world spring-boot project with gradle and groovy.
When I run 'gradle clean build', I am getting below error.
So far I tried,
Even though it is a gradle project, I updated the maven version to latest(3.6.3). Just to be a safer side.
I re-installed my intelliJ IDE
I added maven url as "https:" in build.gradle
After above steps, still I am getting below error. I am not sure what else I am missing.
Though I have given 'https:' url in gradle build file, I am not sure from where it is taking the non-secure url(http).
Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE.
Required by:
project :
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE.
> Could not get resource 'http://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.1.1.RELEASE/spring-boot-dependencies-2.1.1.RELEASE.pom'.
> Could not HEAD 'http://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.1.1.RELEASE/spring-boot-dependencies-2.1.1.RELEASE.pom'. Received status code 501 from server: HTTPS Required
And my gradle build file looks:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.own.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
maven {
url = 'https://repo.maven.apache.org/maven2'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Finally, I figured out where to update the maven url to "https://*" for gradle projects.
$ vi ~/.gradle/init.gradle
then I updated the maven url to secure protocol ("https://...")
allprojects {
repositories {
mavenLocal()
// Any Organization/Company specific repo url goes here
maven {
url "https://repo1.maven.org/maven2"
}
}
}
After above steps, it worked for me and able to build the spring-boot application successfully.
Using start.spring.io, this is the content of the build.gradle generated there:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'groovy'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.codehaus.groovy:groovy'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Note the major differences:
groovy is actually there as plugin and as dependency
the maven repo is secure. As the error message states, you have use
the https endpoint here