jruyi / thrift-gradle-plugin

A gradle plugin for compiling Thrift IDL files using Thrift compiler
Apache License 2.0
48 stars 21 forks source link

Bug: old compiled classes are not deleted #19

Open honourednihilist opened 7 years ago

honourednihilist commented 7 years ago

I worked on a gradle plugin using this one. It looks like I found a bug, but I didn't go deeper to investigate.

I'll use my example project gradle-kafka-deserializers-example to describe how to reproduce the bug.

Clone the repository and build the project:

$ git clone git@github.com:honourednihilist/gradle-kafka-deserializers-example.git
$ cd gradle-kafka-deserializers-example/
$ export THRIFT=/home/user/Programs/thrift-0.9.3/compiler/cpp/thrift
$ ./gradlew build

Let's take a look at list of compiled classes:

$ ls -1 thrift-model/build/classes/java/main/com/github/honourednihilist/gradle/kafka/deserializers/example/model/gen/

YourBaseStruct$1.class
YourBaseStruct.class
YourBaseStruct$_Fields.class
YourBaseStruct$YourBaseStructStandardScheme.class
YourBaseStruct$YourBaseStructStandardSchemeFactory.class
YourBaseStruct$YourBaseStructTupleScheme.class
YourBaseStruct$YourBaseStructTupleSchemeFactory.class
YourCompositeStruct$1.class
YourCompositeStruct.class
YourCompositeStruct$_Fields.class
YourCompositeStruct$YourCompositeStructStandardScheme.class
YourCompositeStruct$YourCompositeStructStandardSchemeFactory.class
YourCompositeStruct$YourCompositeStructTupleScheme.class
YourCompositeStruct$YourCompositeStructTupleSchemeFactory.class
YourContainersStruct$1.class
YourContainersStruct.class
YourContainersStruct$_Fields.class
YourContainersStruct$YourContainersStructStandardScheme.class
YourContainersStruct$YourContainersStructStandardSchemeFactory.class
YourContainersStruct$YourContainersStructTupleScheme.class
YourContainersStruct$YourContainersStructTupleSchemeFactory.class
YourEnum.class
YourException$1.class
YourException.class
YourException$_Fields.class
YourException$YourExceptionStandardScheme.class
YourException$YourExceptionStandardSchemeFactory.class
YourException$YourExceptionTupleScheme.class
YourException$YourExceptionTupleSchemeFactory.class
YourService$1.class
YourService$AsyncClient.class
YourService$AsyncClient$Factory.class
YourService$AsyncClient$request_call.class
YourService$AsyncIface.class
YourService$AsyncProcessor.class
YourService$AsyncProcessor$request$1.class
YourService$AsyncProcessor$request.class
YourService.class
YourService$Client.class
YourService$Client$Factory.class
YourService$Iface.class
YourService$Processor.class
YourService$Processor$request.class
YourService$request_args.class
YourService$request_args$_Fields.class
YourService$request_args$request_argsStandardScheme.class
YourService$request_args$request_argsStandardSchemeFactory.class
YourService$request_args$request_argsTupleScheme.class
YourService$request_args$request_argsTupleSchemeFactory.class
YourService$request_result.class
YourService$request_result$_Fields.class
YourService$request_result$request_resultStandardScheme.class
YourService$request_result$request_resultStandardSchemeFactory.class
YourService$request_result$request_resultTupleScheme.class
YourService$request_result$request_resultTupleSchemeFactory.class

Edit your.thrift and rename YourCompositeStruct to RenameYourCompositeStruct:

$ vi thrift-model/src/main/thrift/your.thrift 

Build the project and take a look at list of compiled classes again:

$ ./gradlew build
$ ls -1 thrift-model/build/classes/java/main/com/github/honourednihilist/gradle/kafka/deserializers/example/model/gen/

RenameYourCompositeStruct$1.class
RenameYourCompositeStruct.class
RenameYourCompositeStruct$_Fields.class
RenameYourCompositeStruct$RenameYourCompositeStructStandardScheme.class
RenameYourCompositeStruct$RenameYourCompositeStructStandardSchemeFactory.class
RenameYourCompositeStruct$RenameYourCompositeStructTupleScheme.class
RenameYourCompositeStruct$RenameYourCompositeStructTupleSchemeFactory.class
YourBaseStruct$1.class
YourBaseStruct.class
YourBaseStruct$_Fields.class
YourBaseStruct$YourBaseStructStandardScheme.class
YourBaseStruct$YourBaseStructStandardSchemeFactory.class
YourBaseStruct$YourBaseStructTupleScheme.class
YourBaseStruct$YourBaseStructTupleSchemeFactory.class
YourCompositeStruct$1.class
YourCompositeStruct.class
YourCompositeStruct$_Fields.class
YourCompositeStruct$YourCompositeStructStandardScheme.class
YourCompositeStruct$YourCompositeStructStandardSchemeFactory.class
YourCompositeStruct$YourCompositeStructTupleScheme.class
YourCompositeStruct$YourCompositeStructTupleSchemeFactory.class
YourContainersStruct$1.class
YourContainersStruct.class
YourContainersStruct$_Fields.class
YourContainersStruct$YourContainersStructStandardScheme.class
YourContainersStruct$YourContainersStructStandardSchemeFactory.class
YourContainersStruct$YourContainersStructTupleScheme.class
YourContainersStruct$YourContainersStructTupleSchemeFactory.class
YourEnum.class
YourException$1.class
YourException.class
YourException$_Fields.class
YourException$YourExceptionStandardScheme.class
YourException$YourExceptionStandardSchemeFactory.class
YourException$YourExceptionTupleScheme.class
YourException$YourExceptionTupleSchemeFactory.class
YourService$1.class
YourService$AsyncClient.class
YourService$AsyncClient$Factory.class
YourService$AsyncClient$request_call.class
YourService$AsyncIface.class
YourService$AsyncProcessor.class
YourService$AsyncProcessor$request$1.class
YourService$AsyncProcessor$request.class
YourService.class
YourService$Client.class
YourService$Client$Factory.class
YourService$Iface.class
YourService$Processor.class
YourService$Processor$request.class
YourService$request_args.class
YourService$request_args$_Fields.class
YourService$request_args$request_argsStandardScheme.class
YourService$request_args$request_argsStandardSchemeFactory.class
YourService$request_args$request_argsTupleScheme.class
YourService$request_args$request_argsTupleSchemeFactory.class
YourService$request_result.class
YourService$request_result$_Fields.class
YourService$request_result$request_resultStandardScheme.class
YourService$request_result$request_resultStandardSchemeFactory.class
YourService$request_result$request_resultTupleScheme.class
YourService$request_result$request_resultTupleSchemeFactory.class

You can see that YourCompositeStruct still exists. But I'd expect that it doesn't.

agemocui commented 7 years ago

This is expected. You have to run "./gradlew clean" to delete obsolete output.

emmenlau commented 7 years ago

Is this in line with the gradle behavior for standard java classes? If you remove a class, is the class-file not automatically purged from the build directory?

honourednihilist commented 7 years ago

@agemocui are you sure?

Gradle incremental builds are supposed to work like builds from scratch, but faster. If I rename or remove a regular java class, then the corresponding class-files will be 'renamed' or removed.

agemocui commented 7 years ago

Gradle achieves incremental builds for Java with deep integration. In this thrift plugin, the general incremental mechanism, which is only to track down to file level instead of "class" level, is used. And what I chose/decided is to rebuild everything when there's an input file deleted, not when a struct is deleted.