vertx-service-factory and code-gen with gradle

1,064 views
Skip to first unread message

trueb...@gmail.com

unread,
Mar 15, 2015, 11:52:32 AM3/15/15
to ve...@googlegroups.com
Is there a way to generate a service proxy (@ProxyGen) using gradle as your build tool? As far as I can see vertx-parent hooks into the maven lifecycle and executes the maven-compile-plugin to perform code generation. I don't see how this can work with gradle.

Julien Viet

unread,
Mar 15, 2015, 12:25:56 PM3/15/15
to ve...@googlegroups.com, trueb...@gmail.com
Hi,

the proxy generation is done via an annotation processor which is a kind of plugin for the java compiler.

bottom line it is not tied to Maven in any kind of sort.

so you need to integrate the annotation processor io.vertx.codegen.CodeGenProcessor with your gradle build at least.

here is a stackoverflow page that talks about annotation processor usage in Gradle : http://stackoverflow.com/questions/15584472/integrating-annotation-processors-with-gradle

let us know how it goes

-- 
Julien Viet
www.julienviet.com

On 15 Mar 2015 at 16:52:34, trueb...@gmail.com (trueb...@gmail.com) wrote:

Is there a way to generate a service proxy (@ProxyGen) using gradle as your build tool? As far as I can see vertx-parent hooks into the maven lifecycle and executes the maven-compile-plugin to perform code generation. I don't see how this can work with gradle.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

trueb...@gmail.com

unread,
Mar 15, 2015, 2:15:19 PM3/15/15
to ve...@googlegroups.com, trueb...@gmail.com
Hi Julien,

thanks for clarifying. 
With your help I could make the proxy-gen work. Here is a draft:

//add a source set for generated classes
sourceSets
{
    generated
{
        java
{
            srcDirs
= ['src/main/generated']
       
}
   
}
}
...
add
[group: 'io.vertx', name: 'vertx-codegen', version: vertxVersion] to your compile dependencies
...
task generateServiceProxy
(type: JavaCompile, description: 'Generates EBServiceProxies') {
    source
= sourceSets.main.java
    classpath
= configurations.compile
    destinationDir
= sourceSets.generated.java.srcDirs.iterator().next()
    options
.compilerArgs = [
           
"-proc:only",
           
"-processor", "io.vertx.codegen.CodeGenProcessor",
           
"-AoutputDirectory=$destinationDir"
   
]
}


compileJava
{
    source sourceSets
.main.java + sourceSets.generated.java
}
compileJava
.dependsOn generateServiceProxy

clean
{
   
delete += sourceSets.generated.java.srcDirs
}


A few remarks:

- there is no mention in the documentation of the mandatory "package-info" file with a @GenModule-annotation. The annotation processor's error message is really not helpful and gives no indication about what's causing the error.
@GenModule(name = "vertx-mongo")
package xxx.xxx.xxx.customer;


import io.vertx.codegen.annotations.GenModule;


- I am not sure why annotations related to code generation and the annotation processor itself are in the same module (same mvn-dependency). This forces me to add a compile dependency on the code generator when all I need are some annotations. To my mind everything but io.vertx.codegen.annotations.* should go into a dedicated module and only be required during build-time/compile time. So basically a build-time dependency.


- Missing Rx-Support makes the proxy generation pretty useless for my purposes. Any plans to add support for Observables? I am happy to open a feature request.



Thanks for helping out.

trueb...@gmail.com

unread,
Mar 18, 2015, 3:00:58 PM3/18/15
to ve...@googlegroups.com, trueb...@gmail.com
This is my final solution. It will generate resources into $outputDir/generated-src and compile them without creating an additional sourceset. Also, both IntelliJ and Eclipse with add the generated classes to the classpath. The jar task will add the compiled output to the jar.

def generateSrcPath="$buildDir/generated-src"
def generatedSrcDir = file("$buildDir/generated-src")


sourceSets
{
    main
{
        java
.srcDirs += generatedSrcDir
        output
.dir(builtBy: 'generateServiceProxy', generateSrcPath)
   
}
}


dependencies
{

    compile libraries
.vertx
   
...

    ...
}




task generateServiceProxy
(type: JavaCompile, description: 'Generates EBServiceProxies') {
    source
= sourceSets.main.java
    classpath
= configurations.
compile
    destinationDir
= generatedSrcDir
    options
.compilerArgs = [

           
"-proc:only",
           
"-processor", "io.vertx.codegen.CodeGenProcessor",

           
"-AoutputDirectory=$generateSrcPath"
   
]
}


compileJava
.dependsOn generateServiceProxy



Arnaud Estève

unread,
Mar 18, 2015, 4:43:17 PM3/18/15
to ve...@googlegroups.com
Thanks a lot for posting the final solution, asked the same question a couple of weeks ago on IRC and I'll definitely need this at some point.

trueb...@gmail.com

unread,
Mar 18, 2015, 5:17:21 PM3/18/15
to ve...@googlegroups.com
Thanks a lot for posting the final solution, asked the same question a couple of weeks ago on IRC and I'll definitely need this at some point.


Happy to help. If you are using an IDE, make sure to add the respective plugin.

apply plugin: idea
apply plugin
: eclipse



If you are using eclipse, you might have to configure the plugin to add the generated dir to the classpath-property.

Arnaud Estève

unread,
Mar 21, 2015, 8:06:18 AM3/21/15
to ve...@googlegroups.com
Thanks, I'm using eclipse indeed.

I really wasn't expecting it, but I didn't need to tweak the eclipse plugin and it works, even after "gradle clean"... Not sure it's a good sign but the Proxy-generated class appears in eclipses's bin folder.

Hakucha

unread,
Oct 18, 2015, 3:22:48 AM10/18/15
to vert.x
Can you have a whole gradle project of  vertx service proxy example (in maven) ? As i can't still use @ProxyGen.
Reply all
Reply to author
Forward
0 new messages