springdoc-openapi-gradle-plugin icon indicating copy to clipboard operation
springdoc-openapi-gradle-plugin copied to clipboard

Add ability to run with a different classpath

Open tsvendsen opened this issue 1 year ago • 2 comments

I want to start the app using an in memory db, so I need to start the bootrun with e.g test classpath.

I've done many attempts to modify the classpath inside the bootRun clause in the plugin, but none of them seems to work. If there is a way already, please let me know, otherwise it would be nice to add this.

tsvendsen avatar Feb 29 '24 07:02 tsvendsen

I second this. I had to create unnecessary mock components to my main classpath to get this plugin working. Test classpath already had such mocks, but they are of course inaccessible from main classpath.

KrohnicDev avatar Apr 10 '24 14:04 KrohnicDev

I might be wrong, but isn't this already working to a certain degree? See https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/e855f9c3aeb776f3d3ef285c80aca748c5a50950/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt#L102-L103

In my case, I want to run the app with a modified profile specifically for the doc generation and want to simply use Testcontainers as a DB replacement:

configurations {
  openApiGenRuntime.extendsFrom(runtimeClasspath)
} 

dependencies {
  openApiGenRuntime 'org.testcontainers:postgresql'
}

openApi {
  apiDocsUrl.set("http://localhost:${randPort}/api-docs")

  customBootRun {
    args.set(["--spring.profiles.active=gen-apidocs", "--server.port=${randPort}"])
    classpath = configurations.openApiGenRuntime
  }
}

Yet, I still run into problems with my modules importing dependencies from within the project (i.e. other submodules). Inspecting the forked process's classpath shows that it points to the dependencies as jars but they are not necessarily created when running this task. You can work around this again by setting classpath = sourceSets.main.compileClasspath + configurations.openApiGenRuntime but then there might be problems with resources being imported by the dependencies (this is where I'm stuck right now).

If there's a leaner solution to this, I'd be happy to know.

usimd avatar May 07 '24 19:05 usimd

@tsvendsen,

There are no plans to support such a feature.

bnasslahsen avatar Jun 22 '24 19:06 bnasslahsen