Open cowwoc opened 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;
@vojtechhabarta Your return type is incorrect. See https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskOutputs.html
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.
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.
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.
@vojtechhabarta Why not just update the version then?
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
).
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.
@bschlosser thanks for sharing the example.
Shouldn't outputFile
field be marked with @OutputFiles
annotation?
The plugin always runs regardless of whether the inputs have changed. When running with
gradle --info
I see:I am expecting
generateTypeScript.outputFile
to be used as the declared output.