ciscoo / cxf-codegen-gradle

Gradle plugin to generate Java artifacts from WSDL
Apache License 2.0
26 stars 6 forks source link

Track WSDL file as task input #13

Closed ciscoo closed 2 years ago

ciscoo commented 3 years ago

See https://github.com/ciscoo/cxf-codegen-gradle/issues/12

pschyska commented 3 years ago

I think what you wrote in #12 about the JavaTask args being an Input is not quite correct. It's true that args are inputs, but I can observe that changes in WsdlOption don't lead to the task being out of date.

E.g. updating markGenerated from false to true. I think the reason is that the out of date check is run before the task is executed, and the args are set in an action of the tasks (after it started executing). Therefore, from the perspective of the JavaTask, it has no inputs when gradle does the up to date checks. Even changing the WSDL option to a non-existing one has no effect. Either the JavaExec args should be set at configuration time, or the whole WSDLOption should be declared as a Task input to WSDL2JavaTask. The former might be preferrable as it's less boilerplate. What was the reason of setting the args only during task execution?

Testing project:

plugins {
    java
    kotlin("jvm") version "1.5.21"
    id("io.mateo.cxf-codegen")
}
group = "io.mateo"
version = "1.0.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib"))
}

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

cxfCodegen {
    wsdl2java {
        register("calculator") {
            wsdl.set(file("src/main/resources/calculatorSeparateXsd.wsdl"))
            markGenerated.set(true)
        }
    }
}
pschyska commented 3 years ago

P.S.: That would also explain the caching failure that triggered my interest ;-)

ciscoo commented 3 years ago

Either the JavaExec args should be set at configuration time,

I think this is the correct way, in fact that how it was in the previous RC.

Delaying the args was a fix for https://github.com/ciscoo/cxf-codegen-gradle/issues/7, but looking back, that may have not been correct.

pschyska commented 3 years ago

I think what would prevent the issue in #7 is to run addToSourceSet and registerCodegenTasks right away, i.e. in the extension as soon as wsdl2java was configured. That way, realization at any point should "just work"?

I have changed it like that, and added a first version with parsing the WSDL and finding all external references. It works in the project above when using gradle cli, but the tests are failing because they can't find wsdl2javaCalculator task.

On the cli, I do see it with

------------------------------------------------------------
Gradle 6.8
------------------------------------------------------------

Build time:   2021-01-08 16:38:46 UTC
Revision:     b7e82460c5373e194fb478a998c4fcfe7da53a7e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (Oracle Corporation 11.0.11+0-adhoc..source)
OS:           Linux 5.13.3 amd64

I'm gonna push my WIP soon and take a break to continue later or tomorrow.

pschyska commented 3 years ago

WIP: https://github.com/pschyska/cxf-codegen-gradle/commit/557a067b2b44eb535bc1a451fe933cb1b5d8e00d

pschyska commented 3 years ago

@ciscoo I'm having issues getting the wsdl2java.configure construct to work. Is this intended usage? This sidesteps the action handler in https://github.com/ciscoo/cxf-codegen-gradle/blob/master/cxf-codegen-gradle/src/main/java/io/mateo/cxf/codegen/CxfCodegenExtension.java#L50 where I'd like to configure the java task when the container is configured. I replaced wsdl2java.configure with wsdl2java {} in the groovy functional test build files and now it works in both kotlin and groovy DSLs. I experimented with make WSDLOption Configurable, and taking a Consumer callback which was then evaluated in the Extions but I couldn't make it work :-(

ciscoo commented 3 years ago

@pschyska this issue is solely for adding the WSDL file itself as input. I think the discussion we've had so far is good in this issue and the last, so I have converted your initial issue to a discussion: https://github.com/ciscoo/cxf-codegen-gradle/discussions/16

Let's continue hashing out finer details or enhancements there.