Gson dependency for grails - maven

Hello I have following GSON dependency in my BuildConfig.Grooovy file
compile 'com.google.code.gson:gson:2.2.4'
and these repos
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenCentral()
grailsCentral()
mavenLocal()
mavenRepo "http://repo1.maven.org/maven2/"
mavenRepo "http://repo.grails.org/grails/libs-releases/"
}
This is a pretty basic question but I am getting following error and dont know how to fix it!
Resolve error obtaining dependencies: Could not find artifact com.google.code.gson:gson:zip:2.2.4 in mavenCentral (http://repo1.maven.org/maven2/) (Use --stacktrace to see the full trace)

What it looks like from the error message is that you have declared the dependency as a grails plugin inside plugins section.
//incorrect, hence it is looking for a .zip artifact instead of a .jar
plugins {
compile 'com.google.code.gson:gson:2.2.4'
}
instead add it as a dependency
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}

Related

How to implement micronaut dependency in grails gradle?

I'm trying to add micronaut dependency in grails build.gradle. And I found no proper solution. And getting the following error.
build.gradle file
dependencies {
*these are the dependencies I would like to add*
// implementation("io.micronaut.reactor:micronaut-reactor")
// implementation("io.micronaut.reactor:micronaut-reactor-http-client")
// implementation("io.micronaut.security:micronaut-security-jwt")
// implementation("io.micronaut.views:micronaut-views-velocity")
// compileOnly("io.micronaut.security:micronaut-security-annotations")
}
I tried adding mavenCentral() and mavenLocal() in the repositories. And it didn't work. Does anyone know how can I implement micronaut dependencies?
Error
grails:test: Could not find io.micronaut.reactor:micronaut-reactor:.
Required by:
project :
You need to tell Gradle what version of the dependencies to pull down.
repositories {
mavenCentral()
}
dependencies {
implementation platform('io.micronaut:micronaut-bom:3.5.2') // <1>
implementation("io.micronaut.reactor:micronaut-reactor")
implementation("io.micronaut.reactor:micronaut-reactor-http-client")
implementation("io.micronaut.security:micronaut-security-jwt")
implementation("io.micronaut.views:micronaut-views-velocity")
compileOnly("io.micronaut.security:micronaut-security-annotations")
}
The Bill of materials (BOM), which contains all the dependency version numbers for the Micronaut Framework 3.5.2 release.

How to ignore bad pom 'inconsistent module descriptor' (version)

I need a dependency which has an inconsistent version number in it's pom.
Apache XmlSchema-Pom has as version SNAPSHOT which is obviously not correct as it should be 1.1.
According to this gradle discussion it should be possible if the maven repository specified as an ivy repo, adding #jar or transitive = false to the dependency, all that didn't work for me
Here my build.gradle with my attempts:
group 'de.company'
version '1.0-SNAPSHOT'
apply plugin: 'maven'
apply plugin: 'java'
repositories {
// specified as ivy repo
// ivy {
// url = mavenCentral().url
// }
mavenCentral()
}
dependencies {
// with #jar and transitive
// compile (group: 'org.apache.ws.commons', name: 'XmlSchema', version: '1.1', ext: 'jar') {
// transitive = false
// }
compile group: 'org.apache.ws.commons', name: 'XmlSchema', version: '1.1'
}
Here is the error message which gradle outputs:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not resolve org.apache.ws.commons:XmlSchema:1.1.
Required by:
de.company:gradle-test:1.0-SNAPSHOT
> Could not resolve org.apache.ws.commons:XmlSchema:1.1.
> inconsistent module metadata found. Descriptor: org.apache.ws.commons:XmlSchema:SNAPSHOT Errors: bad version: expected='1.1' found='SNAPSHOT'
The way i solved this is different, I don't want to touch artifactory pom as i don't have access to artifactory. here is the code you need in gradle.build
repositories {
maven {
url 'http://xxxxx/xx'
metadataSources {
artifact() //Look directly for artifact
}
}
}
As to the current date, there is no actual way of ignoring the validating of the poms from gradle.
Still there are some ways to workaround that.
Try use an other version of that dependency, where the pom is valid
Check other repositories, maybe they have an valid pom for the depedency you want.
that would be in my example for XmlSchema the jcenter repository (XmlSchema from jcenter)
Download the sources by yourself and deploy it into your local/company repository and use this version instead

Gradle NoClassDefFoundError in jar dependency

I have developed a custom Gradle plugin and assembled as jar. This plugin has one dependency:
plugin/build.gradle
dependencies {
compile 'com.jcraft:jsch:0.1.53'
}
I have included my plugin in another consumer project (as jar in libs):
consumer/build.gradle
apply plugin: 'gg-release-plugin'
buildscript {
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
classpath 'com.myplugin.plugin:myplugin:1.0'
}
}
Everything works fine, but when code that uses classes of the dependency com.jcraft:jsch:0.1.53 is executed, I get an error:
java.lang.NoClassDefFoundError: com/jcraft/jsch/JSch
What am I doing wrong? How can I include the dependencies in jar file?
Seems, you've created a plugin jar library with compile time depnedency, that is not included anywhere in your final jar.
You can try to create your plugin jar as a fat jar, using Gradle FatJar plugin or something else. In that case, you'll have a single jar with all the dependent classes inside. But this could lead to problems, if someone will use the same library.
Or you can try to provide a JSch library together with your plugin jar and make a consumer build script dependency like:
buildscript {
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
classpath 'com.myplugin.plugin:myplugin:1.0'
classpath 'com.jcraft:jsch:0.1.53'
}
}
As I know, if you use a Maven repo to publish your plugin, you can provide a pom.xml to describe all the plugin's dependencies, but as I see, you are using a flatDir for it, so, it seems not to be possible.

Gradle fails to resolve spring dependency

I am trying to build my project with the following build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
maven {
url 'https://repo.spring.io/milestone'
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb:1.2.2.RELEASE')
compile('org.springframework.data:spring-data-mongodb:1.7.0.RC1')
compile('org.springframework.cloud:spring-cloud-spring-service-connector')
compile('org.springframework.cloud:spring-cloud-cloudfoundry-connector')
compile 'org.springframework:spring-test:4.1.5.RELEASE'
compile 'de.grundid.opendatalab:geojson-jackson:1.3'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.1'
compile 'org.apache.httpcomponents:httpclient:4.4'
testCompile('junit:junit')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I added the milestone repository because I need the spring-data-mongodb 1.7.0.RC1 dependency. However, there seems to be something wrong with the references of the parent-poms because gradle is unable to fetch the following dependency: org.springframework.data.build:spring-data-parent:1.6.0.RC1
It exits with the following error:
Could not find org.springframework.data.build:spring-data-parent:1.6.0.RC1.
Searched in the following locations:
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
The output of the gradlew build --debug command can be found here: http://pastebin.com/seYRMFQP
The command additionally produced the following output to stdout: http://pastebin.com/atcWQsKF
I already tried to clean my local gradle cache but it did not resolve the problem.
Sorry for the inconvenience, the artifact is currently misplaced in the release repository, though it should be in milestone.
We'll move it to milestone asap. Until that happens please add the release repository url 'https://repo.spring.io/release' to your build.
seems the repositories you defined in your build do not contain the libraries you're looking for. but it seems the lib is available in jcenter. to add jcenter add the following snippet to your build.gradle file:
repositories {
jcenter()
}
cheers,
René

Grails and Sesame

I'm trying to import core libraries of OpenRDF Sesame into a Grails Application.
This is an extract of my BuildConfig.groovy file:
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
}
dependencies {
compile 'org.openrdf.sesame:sesame-core:2.7.7'
}
I get this error message:
Error Could not find artifact org.openrdf.sesame:sesame-core:jar:2.7.7 in grailsCentral (http://repo.grails.org/grails/plugins) (scope: runtime) (Use --stacktrace to see the full trace)
I can't figure out how to solve this issue, the artifact is available on Maven Central:
http://search.maven.org/#artifactdetails%7Corg.openrdf.sesame%7Csesame-core%7C2.7.7%7Cpom
There's no jar there, just a POM file, and it has no dependencies: http://repo1.maven.org/maven2/org/openrdf/sesame/sesame-core/2.7.7/
Looks like you're going to need to specify the individual jar dependencies that you need - e.g. http://repo1.maven.org/maven2/org/openrdf/sesame/sesame-http-client/2.7.7/

Resources