Error on build Spring gradle project generated from Spring Initializr - java

I've created a demo Gradle project called test-jdbc-demo from Spring using some dependencies and change nothing, just unziped and imported on Intellij using Open -> build.gradle file and tried too using Import from default Intellij window. When imported the project is not build and a error about gradle dependencies occurs. I'm using Intellij 2019.3, JDK 1.8 on Ubuntu.
Error
FAILURE: Build failed with an exception.
* Where:
Build file '/home/augusto.cadini/projects/Spring Applications/test-jdbc-demo/build.gradle' line: 2
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.2.4.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.2.4.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
CONFIGURE FAILED in 208ms
build.gradle
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.jdbc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}

This drove me crazy. I was getting the same errors (this is from a clean project generated from Spring Initializr). Turned out it was an issue with the Gradle version. When I ran a build from the command line, I got the following error message
Once I updated gradle it build with no issues.

Related

How to create an executable Jar for Spring Boot using gradle in an offline environment

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

gradle build error: Could not resolve com.android.support:appcompat-v7:28.0.0

Am I not setting up the repo's properly? Because I'd expect springframework below to be resolved quite readily.
could not resolve springframework:
nicholas#mordor:~/NetBeansProjects/hello_odoo$
nicholas#mordor:~/NetBeansProjects/hello_odoo$ gradle clean run
> Task :app:run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:run'.
> Could not resolve all files for configuration ':app:runtimeClasspath'.
> Could not resolve com.android.support:appcompat-v7:28.0.0.
Required by:
project :app > com.oogbox.api:odoo:1.0.4
> Could not resolve com.android.support:appcompat-v7:28.0.0.
> Could not get resource 'http://maven.springframework.org/release/com/android/support/appcompat-v7/28.0.0/appcompat-v7-28.0.0.pom'.
> Could not GET 'http://maven.springframework.org/release/com/android/support/appcompat-v7/28.0.0/appcompat-v7-28.0.0.pom'. Received status code 403 from server: Forbidden
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2s
3 actionable tasks: 3 executed
nicholas#mordor:~/NetBeansProjects/hello_odoo$
the gradle.build file:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.7/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
jcenter()
mavenCentral()
maven { url "http://maven.springframework.org/release" }
maven { url "http://maven.restlet.org" }
}
dependencies {
// Use TestNG framework, also requires calling test.useTestNG() below
testImplementation 'org.testng:testng:7.2.0'
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
// https://mvnrepository.com/artifact/com.oogbox.api/odoo
compile group: 'com.oogbox.api', name: 'odoo', version: '1.0.4'
// providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
// testCompile 'junit:junit:4.12'
}
application {
// Define the main class for the application.
mainClass = 'hello_odoo.App'
}
tasks.named('test') {
// Use TestNG for unit tests.
useTestNG()
}
the hello world at least compiles and runs:
nicholas#mordor:~/NetBeansProjects/hello_odoo$
nicholas#mordor:~/NetBeansProjects/hello_odoo$ gradle clean run
> Task :app:run
Hello World!
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 2s
3 actionable tasks: 3 executed
nicholas#mordor:~/NetBeansProjects/hello_odoo$
build file:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.7/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
jcenter()
mavenCentral()
// maven { url "http://maven.springframework.org/release" }
// maven { url "http://maven.restlet.org" }
maven { url 'https://maven.google.com' }
}
dependencies {
// Use TestNG framework, also requires calling test.useTestNG() below
testImplementation 'org.testng:testng:7.2.0'
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
// https://mvnrepository.com/artifact/com.oogbox.api/odoo
compile group: 'com.oogbox.api', name: 'odoo', version: '1.0.4'
// providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
// testCompile 'junit:junit:4.12'
}
application {
// Define the main class for the application.
mainClass = 'hello_odoo.App'
}
tasks.named('test') {
// Use TestNG for unit tests.
useTestNG()
}
although I'm not clear on the different repo, nor am I so sure this resolves the "problem" and am ready to use the API.

which repository has eXist and how is it added to the classpath with gradle?

Looking to import the eXist database, as well as additional dependencies.
What repositories work best for this requirements?
stack trace for build:
thufir#dur:~/NetBeansProjects/twitterBaseX$
thufir#dur:~/NetBeansProjects/twitterBaseX$ gradle clean build
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.exist-db.thirdparty.com.thaiopensource:jing:20151127.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.pom
- https://repo.maven.apache.org/maven2/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.jar
- https://mvnrepository.com/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.pom
- https://mvnrepository.com/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.jar
- https://jcenter.bintray.com/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.pom
- https://jcenter.bintray.com/org/exist-db/thirdparty/com/thaiopensource/jing/20151127/jing-20151127.jar
Required by:
project : > org.exist-db:exist-core:5.2.0
> Could not find org.exist-db.thirdparty.javax.xml.xquery:xqjapi:1.0-fr.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.pom
- https://repo.maven.apache.org/maven2/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.jar
- https://mvnrepository.com/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.pom
- https://mvnrepository.com/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.jar
- https://jcenter.bintray.com/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.pom
- https://jcenter.bintray.com/org/exist-db/thirdparty/javax/xml/xquery/xqjapi/1.0-fr/xqjapi-1.0-fr.jar
Required by:
project : > org.exist-db:exist-core:5.2.0
* 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 3s
2 actionable tasks: 2 executed
thufir#dur:~/NetBeansProjects/twitterBaseX$
it's only the import for exist-db which seems to be causing trouble:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/5.4.1/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
//
//maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://mvnrepository.com/" }
jcenter()
}
dependencies {
// This dependency is found on compile classpath of this component and consumers.
implementation 'com.google.guava:guava:27.0.1-jre'
// Use TestNG framework, also requires calling test.useTestNG() below
testImplementation 'org.testng:testng:6.14.3'
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.1'
compile group: 'org.basex', name: 'basex', version: '9.2.4'
compile group: 'net.sf.xmldb-org', name: 'xmldb-api', version: '1.7.0'
// https://mvnrepository.com/artifact/org.exist-db/exist-core
compile group: 'org.exist-db', name: 'exist-core', version: '5.2.0'
}
// Define the main class for the application
mainClassName = 'twitterBaseX.App'
test {
// Use TestNG for unit tests
useTestNG()
}
as commenting out that compile group allows a clean build. Presumably it's a question of adding the correct repo's properly?
For eXist-db 5.x.x you need two repositories:
Maven Central for the eXist-db artifacts themselves.
eXist-db's Repository (http://repo.evolvedbinary.com/repository/exist-db/) for some third-party artifacts which cannot be published to Maven Central as they do not meet the requirements for Maven Central.

What is causes a ModuleVersionNotFoundException in Gradle?

I've used Gradle before, but have never configured it myself. I'm running openjdk 11.0.4 and have installed Gradle using the official install guide, including adding it to the windows path. All I've been doing is adding the line:
'''
implementation 'com.github.kittinunf.fuel:fuel:2.2.0'
to my build.gradle file. I'm editing using Intellij. Here is my full build.gradle file:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
}
group 'lastname'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.github.kittinunf.fuel:fuel:2.2.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
When I try to sync the project I get the following from my Gradle tab
gradle_tab_view
The build output I get is this:
4:20:29 PM: Executing tasks ':classes :testClasses'...
> Task :compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.github.kittinunf.fuel:fuel:2.2.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/github/kittinunf/fuel/fuel/2.2.0/fuel-2.2.0.pom
- https://repo.maven.apache.org/maven2/com/github/kittinunf/fuel/fuel/2.2.0/fuel-2.2.0.jar
Required by:
project :
* 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 0s
1 actionable task: 1 executed
4:20:30 PM: Tasks execution finished ':classes :testClasses'.
Any advice on what could be broken or maybe what clearly isn't implemented would be appreciated, this has greatly hindered my work flow, and I feel like it has to be something small or stupid that I'm overlooking. I feel like I'm at war with Gradle to get Fuel to work in my project.
The error output means that Gradle could not find the Fuel dependency in the two locations is searched. Both locations are in https://repo.maven.apache.org/maven2/, which is Maven Central. Gradle looks in this repository as you have told it to through repositories { mavenCentral() }.
However, Fuel is not published to Maven Central. If you use a search site like mvnrepository, you will see where it was found. In this case it says:
Note: this artifact it located at Spring Lib Release repository
(https://repo.spring.io/libs-release/)
But his is misleading, because that is just a mirror as some Spring library apparently depends on it. If you head over to the Github page for Fuel, you will see that it is in reality deployed to Jitpack. So the correct solution is to add Jitpack to the list of repositories in Gradle:
repositories {
maven {
name "jitpack"
url "https://www.jitpack.io"
}
}
This is not all that clear from the Github page as is is only explained in the section for snapshot releases. But it is not all that uncommon to have to do a bit of detective work to track down which repository to use for a given dependency when it is not present in any of the common ones.
By the way, testCompile is deprecated and you should use testImplementation. And since this is a Kotlin project, you will probably want to switch from the Groovy DSL to Kotlin DSL at some point.

Why did heroku build fail with gradle and spring boot?

I'm trying to set basic workspace for Spring boot and gradle.
Everything works perfectly in local and in travis, but in heroku build fails. I don't think the problem is in the actual code, but in the configuration.
Here is my project in github.
build.gradle
plugins {
id 'java'
id 'maven'
id 'jacoco'
id 'org.springframework.boot' version '1.5.3.RELEASE'
}
group = 'org.karlin'
version = '0.1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
bootRepackage {
mainClass = 'gramise.Gramise'
}
repositories {
maven {
url("https://plugins.gradle.org/m2/")
}
}
dependencies {
compile("com.google.code.gson:gson")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql")
compile("org.apache.commons:commons-dbcp2")
compile("com.h2database:h2")
testCompile(group: 'org.springframework.boot', name: 'spring-boot-
starter-test', version:'1.5.3.RELEASE') {
exclude(module: 'commons-logging')
}
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.2.0'
}
task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean
There is heroku build log
-----> Gradle app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Gradle Wrapper...
WARNING: Your application does not have it's own gradlew file.
-----> Building Gradle app...
-----> executing ./gradlew build
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-tools/1.5.3.RELEASE/spring-boot-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar
FAILURE: Build failed with an exception.
* What went wrong:
org/gradle/api/plugins/JavaPlugin
> org.gradle.api.plugins.JavaPlugin
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
You need to check gradlew into Git.
WARNING: Your application does not have it's own gradlew file.
Because you are not doing this, Heroku is using a very old version of Gradle.
If someone else is encountering this problem, this fixed it
I added buildscript in build.gradle
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
Now everything is working, thanks for help.

Categories