What is causes a ModuleVersionNotFoundException in Gradle? - java

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.

Related

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.

Error on build Spring gradle project generated from Spring Initializr

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.

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.

How can I create Gradle tasks correctly?

I'm trying to build tasks to allow me to specify my profile for my spring app using Gradle.
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id "com.diffplug.gradle.spotless" version "3.10.0"
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
spotless {
java {
googleJavaFormat()
licenseHeaderFile 'habicus.license.java'
}
}
group = 'com.remindful'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-websocket')
compile('org.springframework.session:spring-session-core')
compile("com.h2database:h2")
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
testCompile 'junit:junit:4.12'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.1.RELEASE'
}
// TODO: Add prod profile in application-properties
task prod {
run { systemProperty "spring.profiles.active", "prod" }
}
task dev {
run { systemProperty "spring.profiles.active", "dev" }
}
// To force debug on application boot, switch suspend to y
bootRun {
systemProperties System.properties
jvmArgs=["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
tasks.bootRun.dependsOn build
bootRun.mustRunAfter dev
I have two questions:
1) Intellij highlight the tasks with yellow squiggly underline, so I'm wondering if the syntax here is wrong?
2) Do I use gradle-wrapper for something like this or just gradle? I'm trying to better understand the difference.
1) Intellij highlight the tasks with yellow squiggly underline, so I'm wondering if the syntax here is wrong?
Unfortunately, IntelliJ does not support gradle completely, for example, the ext block in the build script is not recognized correctly, so when accessing members defined throught the ext block, IntelliJ fails to resolve its definition & type.
So there's no need for panic when IntelliJ displays a yellow underline, you only need to take notice of the errors reported by the gradle command. If gradle build says OK, then everything is fine.
Meanwhile, IntelliJ is unable to resolve third-party plugins statically, therefore it is also unable to recognize tasks and Task classes added by these plugins. In this case, it will also show this yellowish underline complaining about something like cannot infer argument type.
The solution is to refresh all Gradle projects, by clicking the refresh button on the gradle panel, and if your build script is written correctly, these underlines will most probably vanish. This is because IntelliJ embedds with gradle using the Gradle Tooling API, and during the gradle sync process (fired by refresh all Gradle projects), third-party plugins got resolved and the whole project object model is built, so that IntelliJ would know that nothing is wrong with your tasks.
If gradle build fails, then the problem is with your own build script. On how to write gradle build scripts & tasks correctly, see Authoring Tasks - Gradle User Manual.
2) Do I use gradle-wrapper for something like this or just gradle? I'm trying to better understand the difference.
The Gradle wrapper is explained in the official userguide. To be brief, I would quote:
The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary.
So if you don't have a wrapper script in your project, you should execute gradle wrapper to generate one, and then commit it to your VCS. After that, wherever you previously execute gradle <task> in the command line, you can/should replace it with ./gradlew <task> (in *nix environment) or gradlew.bat <task> (in Windows).
The main difference between using the gradle command directly from the command line and the gradle wrapper script is, that the gradle wrapper script will download the gradle binary and uses it to execute gradle builds if no installed gradle binary is found, while using the the gradle command will only result in an error in such case.
Also, when someone else is using your project, he/she can simply clone the repo and run ./gradlew build (in *nix) or gradlew.bat build (in Windows) and your project will build fluently and successfully, regardless of whether he/she has previously installed a gradle distribution.

Gradle 'Could not resolve all dependencies for configuration' in Jersey/JAX-RS project

I would like to put JSON dependency in the build.gradle, in order to fix the error MessageBodyWriter not found for media type=application/json.
In my previous question I learned that it was very likely that I did not include JSON as dependency in my build.gradle file.
I added the dependency as shown below (line 8, last compile)
apply plugin: 'war'
apply plugin: 'jetty'
dependencies {
compile fileTree(dir: 'lib', include: '**/*.jar')
compile(project(":qa-common"))
compile(project(":alm"))
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.3.10'
}
jettyRun {
httpPort = 8080
reload = 'automatic'
scanIntervalSeconds = 2
daemon = false
}
Now I am getting the error of Could not resolve all dependencies for configuration'
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':qa-automation-console:compile'.
> Cannot resolve external dependency org.glassfish.jersey.media:jersey-media-json-jackson:2.3.10 because no repositories are defined.
Required by:
qaauto:qa-automation-console:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.273 secs
I am checking whether I have included the correct version of gradle and Jersey (in web.xml I see 2.5 but 2.5 still gives the same error). In my jersey server side code the only package related to jersey was import org.glassfish.jersey.server.mvc.Viewable;
Anyone give me a clue what I need to add?
Define repositories in your build.gradle like following.
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
Or following
repositories {
mavenCentral()
}
Gradle Help Chapter 8. Dependency Management Basics 8.5. Repositories gives other examples.
You should also change your dependency according to existing versions. I linked version page since you request "version 2.3.10" which does not exist in maven repository.
dependencies {
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.5'
}

Categories