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

Using thrifty-plugins with the thrifty gradle plugin #489

Closed
amorozov opened this issue Jun 7, 2022 · 9 comments · Fixed by #490 or #494
Closed

Using thrifty-plugins with the thrifty gradle plugin #489

amorozov opened this issue Jun 7, 2022 · 9 comments · Fixed by #490 or #494

Comments

@amorozov
Copy link
Contributor

amorozov commented Jun 7, 2022

This is not an issue but rather a question. Unfortunately I haven't find any other way to ask this question.

Is it possible to use thifty-plugins together with thrifty gralde plugin? How such a build.gradle[.kts] could look like?

I have tried to extend thriftyClasspath for the generateThriftyFiles task like this:

val thrifty: Configuration = configurations.create("thrifty")
dependencies {
    thrifty("org.sample:sample-thrifty-plugins:1.0")
    thrifty("com.microsoft.thrifty:thrifty-compiler:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-java-codegen:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-kotlin-codegen:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-schema:3.0.0")
    ...
}
tasks {
    named<ThriftyTask>("generateThriftFiles") {
        val cp = thrifty.map { it }.toTypedArray()
        thriftyClasspath.from(*cp)
    }
}

but apparently it doesn't work.

However, it does work if I use a JavaExec approach like this:

val thrifty: Configuration = configurations.create("thrifty")
dependencies {
    thrifty("org.sample:sample-thrifty-plugins:1.0")
    thrifty("com.microsoft.thrifty:thrifty-compiler:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-java-codegen:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-kotlin-codegen:3.0.0")
    thrifty("com.microsoft.thrifty:thrifty-schema:3.0.0")
    ...
}
val thriftyGeneratedDir = buildDir.resolve("generated/sources/thrifty")
val thriftSources = arrayOf("sample.thrift")
tasks {
    val generateThrifty = register<JavaExec>("generateThrifty") {
        group = "thrifty"
        doFirst {
            thriftyGeneratedDir.mkdirs()
        }

        workingDir = file("src/main/thrift")
        classpath = thrifty

        mainClass.set("com.microsoft.thrifty.compiler.ThriftyCompiler")
        args = listOf(
            "--out=$thriftyGeneratedDir",
            "--lang=kotlin",
            "--kt-file-per-type",
            "--service-type=coroutine",
            "--omit-file-comments",
            *thriftSources
        )

        inputs.dir(workingDir)
        outputs.dir(thriftyGeneratedDir)

        logging.captureStandardOutput(LogLevel.WARN)
        logging.captureStandardError(LogLevel.ERROR)
    }
}
@benjamin-bader
Copy link
Collaborator

  1. Great question!
  2. It's a very clever idea, trying to extend the worker classpath that way - I wouldn't have thought of that. Too bad it didn't work, though I'm kind of curious about why because it seems like it should.

There's no official way to run plugins via the gradle plugin because the need has never arisen and I haven't previously thought about it. I like your JavaExec solution as a one-off, but will have to think about how to make this work "properly".

@benjamin-bader
Copy link
Collaborator

Oh, I see. Your JavaExec task works because it's going through the "front door", as it were, via the Compiler class. It is the thing that detects your plugin and hooks it up to the code generator. Turns out that I just forgot to do the same orchestration in the gradle plugin. It's a simple fix, thankfully, to make your first effort at extending the classpath work. I'll do that presently; it'll take more thought to expose a proper API for this.

@amorozov
Copy link
Contributor Author

amorozov commented Jun 7, 2022

Thank you very much for the prompt response and for your efforts to solve it! If you need my assistance I will be glad to help.

@benjamin-bader
Copy link
Collaborator

With #490, your first effort at using the gradle plugin (extending the thrifty classpath) should work. As a bonus, you don't even have to specify the other thrifty libs - just your plugin. (the thrifty libs are already on the classpath).

I'll open a new issue to track API design and testing; in the meantime will make a point release.

@amorozov
Copy link
Contributor Author

amorozov commented Jun 7, 2022

Ok, thank you! I will check it as soon as possible.

@benjamin-bader
Copy link
Collaborator

Version 3.1.0-RC02 contains this fix, and should be available on Maven Central and the Gradle Plugin Portal within the next 10-15 minutes.

@amorozov
Copy link
Contributor Author

amorozov commented Jun 8, 2022

Works like a charm, thank you a lot!

@benjamin-bader
Copy link
Collaborator

Glad to hear it - thanks for confirming!

@benjamin-bader
Copy link
Collaborator

Finally coming back to this - soon you'll be able to declare a dependency using the new thriftyTypeProcessor configuration, like so:

dependencies {
  thriftyTypeProcessor "org.sample:sample-thrifty-plugins:1.0" // or any other notation like project(":sample-thrifty-plugins")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants