Gradle not resolving JRE dependency - java

I am a beginner with Gradle projects and am struggling to build a project.
I am receiving this error when running gradle -PmainClass run:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve com.google.guava:guava:28.2-jre.
Required by:
project :
> Could not resolve com.google.guava:guava:28.2-jre.
> Could not get resource 'https://jcenter.bintray.com/com/google/guava/guava/28.2-jre/guava-28.2-jre.pom'.
> Could not GET 'https://jcenter.bintray.com/com/google/guava/guava/28.2-jre/guava-28.2-jre.pom'.
> sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
* 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 11s
1 actionable task: 1 executed
I am trying to run a Java application here by following the first example in this post.
For clarification, I do have an internet connection. I'm wondering if there is some sort of certificate I need.
Here is my build.gradle:
/*
* 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/6.3/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 a CLI application.
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.2-jre'
implementation files('./lib/jython-standalone-2.7.0.jar')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
application {
// Define the main class for the application.
mainClassName = 'Zumi.App'
}
Any help is appreciated. Thanks!

Add mavenCentral() to your repositories block,
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application.
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.2-jre'
implementation files('./lib/jython-standalone-2.7.0.jar')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
application {
// Define the main class for the application.
mainClassName = 'Zumi.App'
}

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.

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.

Gradle build is getting failed

I am quite new to gradle world and I am trying to build a java project and publish the resulting artifacts to the repository.
As part of the build, I am getting the below error message, some pointers on how to fix the below issue would be helpful.
Gradle Build:
$ gradle build --info
Initialized native services in: /var/lib/jenkins/.gradle/native
The client will now receive all logging from the daemon (pid: 4587). The daemon log file: /var/lib/jenkins/.gradle/daemon/4.9/daemon-4587.out.log
Starting 42nd build in daemon [uptime: 4 hrs 26 mins 46.465 secs, performance: 99%]
Using 4 worker leases.
Starting Build
Settings evaluated using settings file '/var/lib/jenkins/gradle_projects/settings.gradle'.
Projects loaded. Root project using build file '/var/lib/jenkins/gradle_projects/build.gradle'.
Included projects: [root project 'hello-world']
> Configure project :
Evaluating root project 'hello-world' using build file '/var/lib/jenkins/gradle_projects/build.gradle'.
FAILURE: Build failed with an exception.
* Where:
Build file '/var/lib/jenkins/gradle_projects/build.gradle' line: 32
* What went wrong:
A problem occurred evaluating root project 'hello-world'.
> Could not find method artifactory() for arguments [build_en65a4pmtkipo6cwvlcm8w7ky$_run_closure3#3ea141a7] on root project 'hello-world' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --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 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.9/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
This error is because you are trying to configure the Artifactory plugin ( artifactory block) but you did not apply the Artifactory plugin to your project.
Try to import the plugin as follow:
buildscript {
// EDIT
repositories {
// ...
jcenter()
}
dependencies {
// ...
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release" // <- this line is missing in your script
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory" // <-- this one is missing in your script
Refer to the plugin official documentation for full configuration examples : https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

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