Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Micronaut Application plugin #7

Closed
jimmymain opened this issue Jun 7, 2021 · 7 comments
Closed

Incompatibility with Micronaut Application plugin #7

jimmymain opened this issue Jun 7, 2021 · 7 comments
Labels
type: bug A general bug
Milestone

Comments

@jimmymain
Copy link

Where:
Build file 'D:\Development\Projects\Zilch\issuer-service\build.gradle' line: 121

* What went wrong:
A problem occurred evaluating root project 'issuer-service'.
> Could not create task ':wsdl2javaGps'.
   > 'wsdl' property is not present

build.gradle has:

plugins {
    id "io.micronaut.application" version "1.3.4"
    id "io.mateo.cxf-codegen" version "1.0.0-rc.3"
    id "com.github.johnrengelman.shadow" version "6.1.0"
}

and later on:

cxfCodegen {
    wsdl2java {
        gps {
            wsdl = file("./src/main/resources/wsdl/service.wsdl")
        }
    }
}

The property seems present and correct.

@ciscoo
Copy link
Owner

ciscoo commented Jun 9, 2021

I was able to reproduce on my Windows 10 machine with the following:

plugins {
    id("io.mateo.cxf-codegen") version "1.0.0-rc.3"
    id("io.micronaut.application") version "1.3.4"
}

repositories {
    mavenCentral()
    // https://github.com/grails/grails-core/issues/11825
    maven {
        url = uri("https://repo.grails.org/artifactory/core")
    }
}

dependencies {
    cxfCodegen("jakarta.xml.ws:jakarta.xml.ws-api:2.3.3")
    cxfCodegen("jakarta.annotation:jakarta.annotation-api:1.3.5")
}


application {
    mainClass.set("com.example.Example")
}

cxfCodegen {
    wsdl2java {
        register("gps") {
            wsdl.set(file("src/main/resources/wsdl/service.wsdl"))
        }
    }
}

If you remove the Micronaut plugin, it works:

plugins {
    id("io.mateo.cxf-codegen") version "1.0.0-rc.3"
-   id("io.micronaut.application") version "1.3.4"
}

I have not worked with Micronaut so I will need to investigate what the various Micronaut plugins are doing to cause the wsdl property to be unset.

From my brief testing, you do not need to execute any wsdl2java tasks for the error to show which is not clear to me why.

@jimmymain
Copy link
Author

I will try this again later. I wonder if it works if the cxf plugin is after the micronaut plugin? It's worth a try, if this is a problem in micronaut, I will happily log the issue there.

@ciscoo
Copy link
Owner

ciscoo commented Jun 9, 2021

I think I narrowed it down to these lines from io.micronaut.application:

https://github.com/micronaut-projects/micronaut-gradle-plugin/blob/v1.5.1/src/main/java/io/micronaut/gradle/MicronautApplicationPlugin.java#L109...L146

More specifically this line: https://github.com/micronaut-projects/micronaut-gradle-plugin/blob/v1.5.1/src/main/java/io/micronaut/gradle/MicronautApplicationPlugin.java#L109

tasks.withType(JavaExec.class, javaExec -> { ... })

That is equivalent to:

tasks.withType(JavaExec.class).all(...)

What I think is happening is that the Micronaut Application plugin is causing the wsdl2java tasks to be realized. Per the Gradle docs (point 7):

Eagerly realizing some tasks may cause a cascade of other tasks to be realized.

Since the Micronaut Application plugin is targeting all JavaExec types, Wsdl2JavaTask types are unfortunately being targeted/configured as well since they are a subclass of JavaExec.

With all of that said, my testing was as follows:

  1. Hack together a test that fails: c9c05cb
  2. Clone the Micronaut Application plugin repo and publish 9.9.9-SNAPSHOT locally
  3. Observe test from (1) fail (passes assertion)
  4. Modify the aforementioned line above and republish locally:
- tasks.withType(JavaExec.class, javaExec -> { ... })
+ tasks.withType(JavaExec.class).configureEach(javaExec -> { ... })
  1. Rerun failing test and it no longer fails for 'wsdl' property is not present

IMO, the Micronaut Application plugin should be more selective as to which JavaExec task it needs to customize. It adds additional dependencies to wsdl2java's classpath which really are not needed and configures other items that are not needed for the wsdl2java tool.

However, I think it is unfair to place the issue solely on Micronaut here. There may be an issue within the cxf-codegen plugin that I am not seeing. I'll need to put together a build scan to get deeper insights as noted in the troubleshooting docs

@ciscoo ciscoo changed the title Simple import of wsdl file produces error: 'wsdl' property is not present. Incompatibility with Micronaut Application plugin Jun 9, 2021
@ciscoo
Copy link
Owner

ciscoo commented Jun 10, 2021

I think I may have a fix:

https://github.com/ciscoo/cxf-codegen-gradle/blob/v1.0.0-rc.3/cxf-codegen-gradle/src/main/java/io/mateo/cxf/codegen/CxfCodegenPlugin.java#L104

@@ -101,7 +101,10 @@ public class CxfCodegenPlugin implements Plugin<Project> {
                                task.setClasspath(configuration.get());
                                task.setGroup(WSDL2JAVA_GROUP);
                                task.setDescription("Generates Java sources for '" + option.getName() + "'");
-                               task.setArgs(option.generateArgs());
+                               // Generate arguments at the very last moment to avoid realization issues.
+                               task.doFirst("generateArgsFor" + name, (exec) -> {
+                                       ((Wsdl2JavaTask) exec).setArgs(option.generateArgs());
+                               });
                        });
                });
        }

My brief testing shows that this works with the Micronaut Application plugin.
I'll need to do more testing to make sure.

I am also not sure if this should be considered a bug or an enhancement

@jimmymain
Copy link
Author

Thanks, that looks awesome, especially as I was thinking the issue might actually be with the micronaut plugin

@ciscoo ciscoo added the type: bug A general bug label Jun 11, 2021
@ciscoo ciscoo added this to the 1.0.0 milestone Jun 11, 2021
@ciscoo ciscoo closed this as completed in 72cb2f2 Jun 11, 2021
pschyska added a commit to pschyska/cxf-codegen-gradle that referenced this issue Jul 25, 2021
…sks in extension

Calling setArgs in a task action makes the whole action have no inputs
during configuration time, which leads to the task always being up to
date. To prevent realization issues (ciscoo#7), the tasks are defined in the
extension when the container is configured, so realizing them at any point
should just work (as they have all the arguments set right away).
@ciscoo
Copy link
Owner

ciscoo commented Aug 8, 2021

Unfortunately the fix for this will need to be reverted since it had undesired consequences. Trying to resolve #13 leads to the same issue as this one, so the fix isn't really a fix.

@ciscoo
Copy link
Owner

ciscoo commented Dec 31, 2021

This has been fixed with #25 and tests show that it now works with the Micronaut plugin. Please give the latest snapshot a try; migration guide here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants