gigaSproule / swagger-gradle-plugin

JAX-RS & SpringMVC supported gradle build plugin to generate Swagger documentation
Apache License 2.0
97 stars 52 forks source link

swagger-gradle-plugin and io.franzbecker.gradle-lombok don't play nicely together #98

Open rherrick opened 6 years ago

rherrick commented 6 years ago

I have a Gradle build in which I'm trying to use both of these plugins. You can see the project and try the build yourself to see the issue. I'm also including a version of build.gradle with the Lombok plugin working and another with the Swagger plugin working.

The problem is that, with both of these plugins configured in the build.gradle, I get the following error:

$ ./gradlew jar

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'xchange'.
> Cannot change dependencies of configuration ':compileOnly' after it has been included in dependency resolution.

I've included the full stack trace as well.

Note that this occurs during the evaluation phase, so it actually breaks the IDE integration as well.

It's definitely the interaction of these two plugins because, if I comment out swagger-gradle-plugin, the project builds fine (of course, I can't use any of the Swagger plugin tasks). If I comment out io.franzbecker.gradle-lombok and manually patch in what that plugin does (add Lombok dependencies for annotationProcessor, compileOnly, and testCompile), the project builds fine (of course, I can't use any of the Lombok plugin tasks).

I'm actually submitting this issue both here and on the Lombok project since I'm really not sure which of the two is the problem (this is issue #47 in the Lombok plugin issues. The failure is clearly coming in the Lombok plugin code, but it seems like the Swagger plugin is doing something that affects the compileOnly configuration, since the Lombok plugin doesn't fail without that. Wherever the root cause is, it's likely that it will affect other plugins down the line as well.

gigaSproule commented 6 years ago

This plugin does need to access the dependency graph, but shouldn't cause problems.

As I use Lombok in most of my projects, why do you need a plugin for it?

Edit: Having looked at the other plugin, I'd argue that delombok isn't required, and unless you use eclipse, it doesn't add any benefit. Also, installing a different version or project would mean having to reinstalling the jar for eclipse continuously, rather than just allowing the user to install latest (and running java -jar lombok.jar isn't that hard). But just my opinion, so I'll see what could be causing an issue.

gigaSproule commented 6 years ago

I've commented on the other issue as well.

gigaSproule commented 6 years ago

So I've found sometime to mess around with this. I assumed you were using the latest version of my plugin, but that works for me. If I use 1.0.4 (or a build from master), the issue disappears. Can you confirm what version you are using?

rherrick commented 6 years ago

Hi @gigaSproule sorry for the late answer. I responded over on the Gradle Lombok plugin issue since you and @franzbecker had a fairly detailed discussion there. The tl;dr version is that I'm using v1.0.4 of the Swagger plugin and v1.14 of the Lombok plugin, i.e. latest available versions. Try creating a new Gradle project with gradle init and making this your build.gradle:

plugins {
    id "com.benjaminsproule.swagger" version "1.0.4"
    id "io.franzbecker.gradle-lombok" version "1.14"
    id "java"
}

repositories {
    jcenter()
}

group = "plugins"
version = "0.0.1-SNAPSHOT"

lombok {
    version = "1.18.2"
    sha256 = "f13db210efa2092a58bb7befce58ffa502e5fefc5e1099f45007074008756bc0"
}

dependencies {
    implementation "io.springfox:springfox-swagger2:2.9.2"
    implementation "io.springfox:springfox-swagger-ui:2.9.2"
}

Or heck, I even reduced it to nothing other than the plugins element:

plugins {
    id "com.benjaminsproule.swagger" version "1.0.4"
    id "io.franzbecker.gradle-lombok" version "1.14"
    id "java"
}

Even the simplest tasks fail:

-> % ./gradlew clean

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'test'.
> Cannot change dependencies of configuration ':compileOnly' after it has been included in dependency resolution.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.9/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 0s

If I comment out either of the Lombok or Swagger plugins it works.

Just for fun, I tried this same build on a totally green server: I run sites on the server but all builds there are done on a Jenkins instance, so I have no build artifacts or tools under my home folder. I installed sdkman then gradle, meaning I got v4.10 which dropped today. I ran gradle init, modified build.gradle with just the plugins element, and ran ./gradlew clean. Same error.

gigaSproule commented 5 years ago

Hey, I have released a newer version and I don't get this error. I think I fixed it in 1.0.5, but obviously hadn't pushed it.

Sorry it took me so long to release it, I've just got no time at all at the moment.

larsgrefer commented 3 years ago

Your plugin still forces the resolution of the compileClasspath and runtimeClasspath configurations during the project configuration phase. Dependency resolution should be deferred into the task execution phase

gigaSproule commented 3 years ago

Hopefully https://github.com/gigaSproule/swagger-gradle-plugin/pull/210 will fix this. Still need to release it though.