Home > Software engineering >  Error while trying to get build script read the java file - Could not resolve all artifacts for conf
Error while trying to get build script read the java file - Could not resolve all artifacts for conf

Time:11-06

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?

CodePudding user response:

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:

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

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