which dependency will be downloaded? - java

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).

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.

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.

Unable to resolve import org.apache.fontbox.util.ResourceLoader in pdfbox 2.0.5

I am trying to get the text color from the pdf document. I am loading PageDrawer.properties using ResourceLoader in constructor of the class as given below. I have defined pdfbox version to 1.5.0 in build.gradle but it is downloading pdfbox version 2.0.5
public PdfTest() throws IOException {
super(ResourceLoader.loadProperties(
"org/apache/pdfbox/resources/PageDrawer.properties", new Properties()));
super.setSortByPosition(true);
}
By above code I am not able to load property "import org.apache.fontbox.util.ResourceLoader".
Does anyone have any idea why pdfbox 2.0.5 is donloaded instead of 1.5.0? Also how to resolve ResourceLoader issue?
build.gradle
group 'abc'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.3'
}
I tried it with IntelliJ it was downloading 1.8.3, but on Android Studio(2.3.2) it was downloading 2.0.5.

Gradle doesn't find Google Protobuf package

I am trying to setup Google protobuf with netty, but when I start compilation gradle first download google protobuf (at least at the first attempt) but then at compilation it just tells me :
/src/main/java/GameMoveOuterClass.java:1536: error: package com.google.protobuf.GeneratedMessageV3 does not exist
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
here is my build.gradle :
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
dependencies {
compile group: 'io.netty', name: 'netty-all', version: '4.1.5.Final'
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.4.1'
}
jar {
manifest {
attributes("Main-Class": 'server.Server',
"Class-Path": configurations.compile.collect { it.getPath() }.join(' '))
}
}
If someone knows what's wrong, please let me know
Thanks
You're using the version 2.4.1 of protobuf which doesn't come with GeneratedMessageV3.
Update to a new version of protobuf which include this class like the 3.0.0
dependencies {
compile group: 'io.netty', name: 'netty-all', version: '4.1.5.Final'
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0'
}
Using the maven central advanced search for com.google.protobuf.GeneratedMessageV3 it seems that the class is in com.google.cloud:google-cloud-nio:xxx or maybe com.trueaccord.scalapb:protobuf-runtime-scala_yyy:zzz. I'm guessing you'll need to add one of these to your classpath.
I am not familiar with Gradle but it looks to me like you are mixing new protobuf generated code with an older protobuf library, which is not supported. The GeneratedMessageV3 class was added only recently (around 3.0 I believe), and so new generated code that references that class cannot be linked against an older library which does not include it.
In my scenario, both my app and library module should add
implementation 'com.google.protobuf:protobuf-javalite:3.9.1'
even app has a dependency on library

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