Gradle not resolving mavenLocal() dependency - maven

I have a problem with resolving local dependency. I have a lib that I want to provide across my projects. So I've published it locally. The build.gradle looks like this:
...
plugins {
...
id("maven-publish")
...
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.wintermute.chatserver.core"
artifactId = "core"
version = "1.0"
from(components["java"])
}
}
}
In the other project, which is requiring the dependency I've added in the build.gradle this:
repositories {
mavenLocal()
mavenCentral()
}
But when I try to resolve the dependencies gradle complains about not resolvable dependency:
Could not resolve com.wintermute.chatserver.core:core:1.0.
Required by:
project :
It was successfull one time, then I've deleted the cache and since this it does not work anymore. Why is that? What I am doing wrong?

Related

Gradle is unable to locate the bintray repository for kotlinx-serialization

I am trying to use kotlinx.serialization and have had just no luck. Here is the pertinent portion of the build.gradle
buildscript {
ext.kotlin_version = '1.3.71'
repositories {
mavenCentral()
google()
jcenter()
maven("https://kotlin.bintray.com/kotlinx")
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
This dies on the vine:
Could not find method maven() for arguments [https://kotlin.bintray.com/kotlinx]
on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler
What is an up-to-date way to incorporate kotlinx-serialization ?
It looks like the actual version for kotlinx.serialization is 1.3.70, not 1.3.71 At least their master branch depends on 1.3.70 kotlin components
The arguments of method maven in org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler is Closure,and the context object is type org.gradle.api.artifacts.repositories.MavenArtifactRepository,so the correct script would be like
repositories {
mavenCentral()
maven {
url="https://kotlin.bintray.com/kotlinx"
}
}
what's more,kotlinx.serialization exists in mavencentral,so there is no need to add your custom maven repository

Maven - Publishing Multiple Sub-Modules/Artifacts

I have a Kotlin project organised like so:
project-name
> project-name-core
> project-name-domain
My gradle publishing script is set up like this:
publishing {
repositories {
mavenLocal()
}
publications.all {
pom.withXml(configureMavenCentralMetadata)
}
publications {
mavenPublication(MavenPublication) {
from components.java
groupId 'com.project'
artifactId 'project-name'
artifact sourcesJar
artifact javadocJar
}
}
}
When I run ./gradlew publishToMavenLocal I can see project-name in the local repository cache, but not project-name-core or project-name-domain.
How do I configure gradle to publish my sub-modules to the maven local repository cache?
Best guess is that you only applied the publishing plugin to the root project and not the subprojects.
If you intend to publish the root project (src/) in addition to the subprojects, then you should move the configurations to the allprojects block:
allprojects {
publishing {
publications.all {
pom.withXml(configureMavenCentralMetadata)
}
publications {
mavenPublication(MavenPublication) {
from components.java
groupId 'com.project'
artifactId 'project-name'
artifact sourcesJar
artifact javadocJar
}
}
}
}
Otherwise if you only want to publish the subprojects, then replace allprojects with subprojects
Also, you don't need to add configure the repositories with mavenLocal().

How to avoid duplication of children repositories in a parent project

I have a multi-project build with the following structure:
Root project 'just-another-root-project'
+--- Project ':producer'
\--- Project ':consumer'
The root settings.gradle file:
rootProject.name = 'just-another-root-project'
include 'consumer', 'producer'
...connects created modules.
The producer.gradle file:
plugins {
id 'java-library'
}
group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}
dependencies {
implementation 'com.sun:tools:1.7.0.13'
}
...has an external dependency (com.sun.tools) that is not published in Maven Central therefore I've added a link to the Nuiton repository.
The consumer.gradle file:
plugins {
id 'java'
}
group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
annotationProcessor project(':producer')
}
The build described above is not working! To make it so I was enforced to duplicate all repositories from producer.gradle into consumer.gradle. So the question is how to build the root project without the excessive dependency duplication? How to do it in the right way? Thanks for any answer or hint :)
UPDATE 1:
I get the following error when try to build the project with files shown above:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':consumer:compile'.
> Could not find com.sun:tools:1.7.0.13.
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.pom
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.jar
Required by:
project :consumer > project :producer
You can configure repositories directly in the root project like that:
root project build.gradle:
// configure repositories for all projects
allprojects {
repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}
}
EDIT (from you comment on other response)
You can also define only mavenCentral() repository on root project level (it will be added to repositories for all projects) and configure http://maven.nuiton.org/release repository only for producer subproject :
root project
repositories {
// will apply to all project
mavenCentral()
}
producer project
repositories {
maven {
url 'http://maven.nuiton.org/release/'
}
// mavenCentral inherited from root project
}
consumer project
// no need to re-define repositories here.
There is a section in an official gradle tutorial dedicated to this:
https://guides.gradle.org/creating-multi-project-builds/#configure_from_above
The root project can configure all projects:
allprojects {
repositories {
jcenter()
}
}

Could not configure Gradle project (Kotlin code)

I am a pretty fresh in Gradle. I'm trying to build up a project Kotlin code with Gradle.
I have spent some time to learn that by following these instructions: https://kotlinlang.org/docs/reference/using-gradle.html
And so far, I have not succeeded in it and got some errors.
My build.gradle is shown below:
group = "kotlin"
version = "1.0-SNAPSHOT"
buildscript {
ext.kotlin_version = '1.2.50'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
And I got the following error
org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
....
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50.

How to force a specific dependency version in a gradle buildscript

There's an issue for the gradle-docker-plugin and SpringBootVersion 2.0.0.M4
M4 uses a newer jersey client and using the docker-plugin ends in an Exception:
ERROR com.github.dockerjava.core.async.ResultCallbackTemplate - Error during callback
java.lang.IllegalStateException: InjectionManagerFactory not found.
at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:98)
at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:68)
at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:432)
at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:826)
at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285)
at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:143)
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:112)
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:108)
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:99)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:456)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:357)
at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
My BuildScript in my main project:
buildscript {
ext {
springBootVersion = "2.0.0.M4"
}
repositories {
maven { url "https://repo.spring.io/plugins-snapshot" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
....
As you can see, we load the spring-boot-gradle-plugin version=2.0.0.M4 and all its dependencies.
My subproject build.gradle:
apply plugin: "org.springframework.boot"
apply from: "docker.gradle"
....
Most important the docker.gradle file in the same directory as the build.gradle of the subproject:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.0.11'
}
}
apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin
import com.bmuschko.gradle.docker.tasks.image.*
...
task buildImage(type: DockerBuildImage, dependsOn: copyDockerFiles) {
version.release = true
dockerFile = file("${projectDir}/build/docker/Dockerfile")
inputDir = file("${projectDir}/build/docker")
tags = ['...']
}
My Questions:
How do I know which Version of the jersey client loads SpringBoot 2.0.0.M4?
How do I force gradle in docker.gradle to use a specific version of the jersey client?
Adding to the classpath didnt work. I think gradle will just use the newest version, wich will be loaded by SpringBoot 2.0.0.M4
You have to add the following in your build.gradle dependencies as pointed in: This Link
dockerJava 'com.nirima:docker-java-shaded:0.16.2'
dockerJava 'org.slf4j:slf4j-simple:1.7.5'
dockerJava 'cglib:cglib:3.2.0'
After that you have to separate "buildImage" and "tagImage" tasks as suggested in This link
I have tested this with: spring boot 2.0.0.M6
I simply did:-
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
classpath "org.mozilla:rhino:1.7.14"
classpath ( group: 'org.apache.commons', name: 'commons-text'){
version{
strictly '1.10.0'
}
}
}

Resources