Not able to add dependency through build.gradle file - java

Whenever i am trying to add dependency in the project through build.gradle , it is not able to add dependency. Instead it throws warning as
Could not resolve: junit:junit:4.12
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.10.1/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE SUCCESSFUL in 1s
I have tried every hook to resolve it, but was not able to.
Please find below build.gradle file which i am using
apply plugin: 'java'
apply plugin: 'idea'
group 'practice'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}

As per mvnrepository.com, for Gradle it has been mentioned as
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.12'
The link is given below.
https://mvnrepository.com/artifact/junit/junit/4.12
If it does not work, try to add the repository as given below.
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
junit version 12 also available in maven repo, you can check following link.
http://repo1.maven.org/maven2/junit/junit/4.12/
Sometimes, we have seen sporadic issue because of corrupt file.
You can delete the .gradle file and you can rerun with command like gradle clean build.

Related

Multiple Repositories in build.gradle is not working (jzy3d) (MultiModuleProject)

I've got a problem with my Java project in gradle. I'm using several dependencies with gradle, one of it is the jzy3d.api. I have included it in the build.gradle file and added the url to the repositories but it doesn't find it. I've added the repository for it as it is located here: http://maven.jzy3d.org/releases/org/jzy3d/jzy3d-api/1.0.2/
But the Error Message seems like that it isn't searching there. Can please someone tell me why?
Here is my build.gradle and the Error Message:
plugins {
id 'java'
id 'idea' // optional, for IntelliJ IDEA project
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
maven {
url "https://maven.jzy3d.org/releases"
}
mavenCentral()
}
dependencies {
testCompile 'org.junit.jupiter:junit-jupiter:5.6.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
compile group: 'org.jzy3d', name: 'jzy3d-api', version: '1.0.2'
compile group: 'org.jfree', name: 'jfreechart', version: '1.5.0'
}
Execution failed for task ':BusinessLayer:compileJava'.
> Could not resolve all files for configuration ':BusinessLayer:compileClasspath'.
> Could not find org.jzy3d:jzy3d-api:1.0.2.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/jzy3d/jzy3d-api/1.0.2/jzy3d-api-1.0.2.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :BusinessLayer > project :DataLayer
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
When I'm adding something to the url, for example url "https://maven.jzy3d.org/releases/maven2" the Error Message says:
Could not find org.jzy3d:jzy3d-api:1.0.2.
Searched in the following locations:
- https://maven.jzy3d.org/releases/maven2/org/jzy3d/jzy3d-api/1.0.2/jzy3d-api-1.0.2.pom
- https://repo.maven.apache.org/maven2/org/jzy3d/jzy3d-api/1.0.2/jzy3d-api-1.0.2.pom
So I think that for some reason it don't want to search in the https://maven.jzy3d.org/releases directory...

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")
}

Gradle not recognizing classes

I am using IntelliJ and I tried importing a project from github using gradle. For some reason it seems to not be working. When I worked on android all I did was add it to the dependencies and everything worked fine. But I did the same thing here and nothing works. Does anyone have any idea on how to fix this? All I did was create a project and add the dependencies and URL to the gradle file. I then copied and pasted the test code from the github repo and I cant import the files.
Thanks
group 'Project'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
url "https://dl.bintray.com/patriques82/maven"
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.patriques:alphavantage4j:1.2'
}
Maybe instead of
url "https://dl.bintray.com/patriques82/maven"
it should be
maven{
url "https://dl.bintray.com/patriques82/maven"
}
?

Gradle IntelliJ add java dependencies

I have created new Gradle Java project on IntelliJ and added the library like normally do in Android Studio.
Gradle is not getting the library and compiling it.
Build file.
group 'asynjava'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "io.reactivex.rxjava2:rxjava:2.x.y"
}
I couldn't import the library inside my java files.
Is there any settings I have missed ?
compile 'io.reactivex.rxjava2:rxjava:2.1.2'
You have to specify the complete version info, the minor version numbers in particular.

gradle unable to find artifact in maven repository

I am doing a simple gradle build and I have deployed a particular artifact to my internal sonatype maven repo
My build.gradle file looks like this:
apply plugin: 'java'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
maven {url "http://maven.ebay.com/nexus/content/repositories/sre-snapshots/"}
}
dependencies {
compile group: "com.typesafe", name: "config", version: "1.3.0"
//compile project(':metrics')
compile group: 'com.ebay.telemetry', name: 'client-library', version: '0.1-SNAPSHOT'
compile group: "org.slf4j", name: "slf4j-jdk14", version: "1.7.12"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
I run this command on the command line: gradle build
I get this error:
> Could not find net.alchim31:metrics-influxdb:0.7.1-ebay-SNAPSHOT.
Searched in the following locations:
https://repo1.maven.org/maven2/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/maven-metadata.xml
http://maven.ebay.com/nexus/content/repositories/sre-snapshots/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/maven-metadata.xml
http://maven.ebay.com/nexus/content/repositories/sre-snapshots/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/metrics-influxdb-0.7.1-ebay-20150708.054833-4.pom
http://maven.ebay.com/nexus/content/repositories/sre-snapshots/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/metrics-influxdb-0.7.1-ebay-20150708.054833-4.jar
However when I go to http://maven.ebay.com/nexus/content/repositories/sre-snapshots/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/
I see the following files :
metrics-influxdb-0.7.1-ebay-20150708.054830-3.pom
metrics-influxdb-0.7.1-ebay-20150708.054830-3.jar
So why is gradle looking for metrics-influxdb-0.7.1-ebay-20150708.054833-4.jar when my repo has metrics-influxdb-0.7.1-ebay-20150708.054830-3.jar
It seems like you have declared another dependency besides the one you showed above. It should probably look something like this:
compile group: 'net.alchim31', name: 'metrics-influxdb', version: '0.7.1-ebay-SNAPSHOT'
If you find this dependency declaration, you might also find the source of the problem.
The second possibility is, that your maven-metadata.xml (at http://maven.ebay.com/nexus/content/repositories/sre-snapshots/net/alchim31/metrics-influxdb/0.7.1-ebay-SNAPSHOT/maven-metadata.xml) is messed up and points towards the nonexisting build 4.

Categories