Gradle IntelliJ add java dependencies - java

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.

Related

Not able to add dependency through build.gradle file

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.

Intelliji-idea cannot find jar on web

I try to add some import for groovy file.
import groovyx.net.http.RESTClient
import org.apache.http.auth.AuthScope
import org.apache.http.auth.NTCredentials
Try to use option "Find jar on web". As a result I see message "No libraries found for groovyx.net.http.RESTClient".
Same problem was for java projects with adding junit and jsoup libraries, but I just downloaded them.
Where can be a problem?
https://repo1.maven.org/maven2
https://repository.jboss.org/nexus/content/repositories/public/
are used as remote jar repositories
build.gradle file content:
apply plugin: "groovy"
group = "ru.ftc.cs.test"
version = "1.0.0"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "http://diesel.ftc.ru:8080/nexus/content/groups/public/" }
}
dependencies {
testCompile group: "org.codehaus.groovy" , name: "groovy-all" , version: "2.4.5"
testCompile group: "org.codehaus.groovy.modules.http-builder" , name: "http-builder", version: "0.7.1"
testCompile group: "org.spockframework" , name: "spock-core" , version: "1.0-groovy-2.4"
}
Decision:
I need only to run build.gradle correct way to solve a problem.

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

Why intelliJ IDEA dependency scope is "provided" instead of "compile"?

I would like IntelliJ IDEA to have my libraries as "compile" scope instead of "provided" scope. This is a part of my gradle file:
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// Logging
compile 'ch.qos.logback:logback-classic:1.2.1'
compile 'com.getsentry.raven:raven-logback:7.8.2'
// BigQuery
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.apis:google-api-services-bigquery:v2-rev227-1.20.0'
// Configuration management
compile 'commons-configuration:commons-configuration:1.10'
//Json
compile 'org.json:json:20160810'
//Kafka
compile "org.apache.kafka:kafka-clients:0.10.1.1"
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.assertj:assertj-core:3.0.0'
testCompile 'org.mockito:mockito-all:1.10.19'
}
task wrapper(type: Wrapper) {
gradleVersion = '3.4'
}
The scope always reverts to "provided" in the dependency tab which is very annoying:
I am running:
IntelliJ IDEA 2016.3.4
Build #IC-163.12024.16, built on January 31, 2017
JRE: 1.8.0_112-release-408-b6 x86_64
It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4:
IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
original bug report in the Gradle project with more details
comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA
It's already fixed in 2017.1 EAP build.
You can use Gradle 3.3 or older as a workaround until IDEA 2017.1 is released.

which dependency will be downloaded?

I have a build script:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group : 'org.hibernate', name : 'hibernate-core', version :'4.+'
testCompile group : 'junit', name : 'junit', version: '4.+'
}
My question is what exactly version will be downloaded? The latest available version or random? What if some version, satisfies 4.+ restricon are incompatible?
This is about downloading, not uploading. 4.+ will resolve to the latest 4.x version. Not sure I understand your other question about compatibility (you'd have to explain in more detail).

Categories