vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client
MIT License
1.14k stars 237 forks source link

Incremental builds #338

Open cowwoc opened 5 years ago

cowwoc commented 5 years ago

The plugin always runs regardless of whether the inputs have changed. When running with gradle --info I see:

Task ':trading:websocket-protocol:generateTypeScript' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Running TypeScriptGenerator version 2.11.472
...

I am expecting generateTypeScript.outputFile to be used as the declared output.

vojtechhabarta commented 5 years ago

I tried to add generateTsTask.getOutputs().file(...); to TypeScriptGeneratorPlugin class. It worked on Gradle 4 but failed on Gradle 5 with error:

java.lang.NoSuchMethodError: org.gradle.api.internal.TaskOutputsInternal.file(Ljava/lang/Object;)Lorg/gradle/api/tasks/TaskOutputs;
cowwoc commented 5 years ago

@vojtechhabarta Your return type is incorrect. See https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskOutputs.html

vojtechhabarta commented 5 years ago

Return type changed between versions 2 and 5. https://docs.gradle.org/2.1/javadoc/org/gradle/api/tasks/TaskOutputs.html https://docs.gradle.org/3.0/javadoc/org/gradle/api/tasks/TaskOutputs.html https://docs.gradle.org/4.0/javadoc/org/gradle/api/tasks/TaskOutputs.html https://docs.gradle.org/5.0/javadoc/org/gradle/api/tasks/TaskOutputs.html So when the code was compiled against version 2.1 it didn't work with version 5.

cowwoc commented 5 years ago

I assume you're able to fix the plugin code then?

Another (related) suggestions: the plugin execution should dependsOn the jar task of any Java compile dependencies. Currently, you load all classes found on the classpath based on all compile dependencies. However, in our project the build was doing a clean build so you were trying to load a class after it was deleted but before it was recreated so we were getting a NoClassDefException. If you dependsOn the jar task of such dependencies the problem goes away.

vojtechhabarta commented 5 years ago

I think it is not possible to make it work without updating the version.

For your second suggestion PR is welcomed if you want to spend some time with it. It also should be possible to achieve this in build.gradle file.

cowwoc commented 5 years ago

@vojtechhabarta Why not just update the version then?

vojtechhabarta commented 5 years ago

I assume your question is rhetorical and you know the answer 😏 Anyway, I will consider updating it. It should also be possible to set the output in build script (as well as dependsOn).

bschlosser commented 5 years ago

I agree it'd be nice if the plugin set the inputs and outputs by default, but its pretty easy to do yourself.

Here's a sample

generateTypeScript.inputs.dir(file('src/main/java/com/something'))
generateTypeScript.inputs.property('classPatterns', generateTypeScript.classPatterns)
generateTypeScript.outputs.file(generateTypeScript.outputFile)

You may have multiple input directories, they would need to be specified, and if you have other configuration options that have the potential to change, you'd want to add them as input properties too.

vojtechhabarta commented 5 years ago

@bschlosser thanks for sharing the example.

olegshtch commented 5 years ago

Shouldn't outputFile field be marked with @OutputFiles annotation?