Error while trying to get build script read the java file - Could not resolve all artifacts for configuration ':classpath' - spring-boot

I'm trying to follow this by adding my own custom java file into the classpath
https://github.com/gigaSproule/swagger-gradle-plugin#model-converters
This is shown in the example above
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.custom:model-converter:1.0.0'
}
}
...
swagger {
apiSource {
...
modelConverters = [ 'com.custom.model.Converter' ]
}
}
This is my code
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.test.app.profile.component.MyOpenApiCustomiser:1.0.0")
}
}
swagger {
apiSource {
...
modelConverters = [ 'com.test.app.profile.component.MyOpenApiCustomiser' ]
}
}
This is the error I'm getting
A problem occurred configuring root project 'profile'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.test.app.profile.component.MyOpenApiCustomiser:1.0.0:.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I tried removing 1.0.0
Caused by: org.gradle.api.IllegalDependencyNotation: Supplied String module notation 'com.test.app.profile.component.MyOpenApiCustomiser' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'
Not sure how I would get my build script to the use the MyOpenApiCustomiser in my spring boot application
Is there any other way or how to fix this?

The classpath dependency given in the buildscript.dependencies {} block needs to be a external library, given in the standard group:modulde:version notation; in the example from github project it's "com.custom : model-converter : 1.0.0" ( it's a "fake" library, does not really exist in maven central repo, it's just an example)
In your case, it seems you try to refer your class MyOpenApiCustomiser as the classpath library , which cannot work. It needs to be a real library.
If you want to use your own Converter, you'll need to implement it in another library/module, publish it to a private repository and then consume it in your buildscript classpath.
Another simpler way, would be to implement this converter as a class within the buildSrc project: these classes will then be automatically available in your build script classpath, and you can use it in the apiSource configuration.
Sample:
In your buildSrc project
build.gradle
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
implementation "io.swagger:swagger-core:1.6.2"
}
Your custom ModelConverter class goes under src/main/java, e.g. com.sample.MyCustomConverter
In your root build.gradle script:
You can reference your MyCustomConverter class, it's already available in the script classpath, no need to define a classpath dependency in buildscript
swagger {
apiSource {
modelConverters = [ 'com.sample.MyCustomConverter' ]
// ....

Related

How to override a plugin dependency in a Gradle conventions plugin

I'm using Gradle's conventions as described here:
https://docs.gradle.org/current/samples/sample_convention_plugins.html
And in the convention plugin, I'm applying a plugin (io.freefair.gradle:lombok-plugin:6.5.1) however I now need to override a dependency that it uses (I need org.projectlombok:lombok:1.18.22 not 1.18.24)
I've tried this:
buildscript {
dependencies {
classpath 'org.projectlombok:lombok:1.18.22'
}
}
plugins {
id 'groovy-gradle-plugin'
}
...
dependencies {
implementation 'io.freefair.gradle:lombok-plugin:6.5.1'
...
implementation 'org.projectlombok:lombok:1.18.22'
}
But version 1.18.24 was used. I've also tried adding this to my build.gradle:
buildscript {
dependencies {
classpath 'org.projectlombok:lombok:1.18.22'
}
}
plugins {
id 'billforward.java-conventions'
}
but still 1.18.24 was used.
As an aside, the two underlying issues I'm trying to solve are:
https://github.com/freefair/gradle-plugins/issues/549 - Resolved in 6.5 of lombok-plugin
https://github.com/projectlombok/lombok/issues/3180 - Broken in 1.18.24 of lombok
The lombok version used by io.freefair.lombok can be customized by using the lombok extension property:
plugins {
id "io.freefair.lombok" version "6.5.1"
}
lombok.version = "1.18.22"
This is documented here: https://docs.freefair.io/gradle-plugins/6.5.1/reference/#_io_freefair_lombok_base
Adding lombok itself to the buildscript classpath (or the runtime classpath of your gradle plugin) will not do anything.

Gradle not resolving mavenLocal() dependency

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?

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

Gradle plugin that loads org.springframework.boot into projects

I'm writing a custom gradle plugin Foo and I want to load the org.springframework.boot plugin
into projects that apply the Foo plugin. I can load various other plugins this way, but this
particular plugin doesn't want to behave the same way.
Foo build.gradle
buildscript {
ext {
springBootVersion = "2.1.3.RELEASE"
}
}
apply plugin: "groovy"
repositories {
maven { url "http://custom.repo/blah" }
}
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
Foo plugin
class BuildPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
project.repositories {
maven { url "http://custom.repo/blah" }
}
project.plugins.apply("org.springframework.boot")
}
}
Project build.gradle
buildscript {
dependencies {
classpath files("/some/cool/path/foo-plugin.jar")
}
}
apply plugin: "com.whatever.foo-id"
Project build output
$ ./gradlew --stacktrace clean build
FAILURE: Build failed with an exception.
* Where:
Build file '/cool/project/location/bar/build.gradle' line: 40
* What went wrong:
A problem occurred evaluating root project 'bar'.
> Failed to apply plugin [id 'com.whatever.foo-id']
> Plugin with id 'org.springframework.boot' not found.
Is it possible to apply a plugin 1 from plugin 2 where plugin 1 is a classpath dependency?
This isn't possible. The classpath is what pulls in the plugins, so it is impossible for them to modify the thing before they are pulled in.

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