Add initial version of Gradle build files#403
Conversation
|
|
||
| description = 'Google Ads API client library for Java examples' | ||
|
|
||
| public class ExampleRunnerTask extends JavaExec { |
There was a problem hiding this comment.
Is this class only needed to allow the user to specify without the com.google.... prefix? If so is there perhaps an easier way to do this? The gradle build files are so pretty, it's a shame to put java boilerplate in them ;-)
There was a problem hiding this comment.
This seemed the best way to address the fact that this project has multiple "Main" classes.
The better, more Gradle-y way would be to have a single main class and to build the subproject as a Java application. Then you could just call ./gradlew run --args.... This would, of course, involve some refactoring of the project.
There was a problem hiding this comment.
Could we move this to the buildSrc directory to simplify the build file here?
There was a problem hiding this comment.
Doing so would then apply the task to all subprojects, i.e. calling ./gradlew runExample ... would run this code for the annotation processor, library, examples, and migration examples subprojects. You could instead call ./gradlew google-ads-examples:runExample ..., but that seems like an extra inconvenience when the task only applies to the one subproject.
There was a problem hiding this comment.
See related response to Josh's question below.
|
|
||
| description = 'Google Ads API client library for Java examples' | ||
|
|
||
| public class ExampleRunnerTask extends JavaExec { |
There was a problem hiding this comment.
Is there a way to have this for the migration examples project as well, without duplication?
There was a problem hiding this comment.
Good point, I didn't explicitly test those. I'll adjust and test.
There was a problem hiding this comment.
The migration examples should of course still be runnable from IntelliJ.
There was a problem hiding this comment.
Will test moving the task code into the top-level build files, then filtering for which subproject to apply them to.
There was a problem hiding this comment.
Restructured; task code is now in buildSrc, and there are now two executable tasks: runExample, as before, and runMigrationExample.
| dependencies { | ||
| implementation 'com.squareup:javapoet:1.11.1' | ||
| implementation 'javax.annotation:javax.annotation-api:1.3.2' | ||
| implementation 'com.google.api:gax:1.50.1' |
There was a problem hiding this comment.
Does gax need to be here, given it's in java-conventions?
There was a problem hiding this comment.
I actually added this in only to match the dependencies from the Maven POM files:
. This one is 1.50.1, while the rest are 1.60.1.This line can be removed if this subproject doesn't need to be pegged to 1.50.1.
There was a problem hiding this comment.
The effective version here for users will be the one from the main project (since it's shallower in the dependency hierarchy). We should just remove this (so we're on 1.60.1).
| dependencies { | ||
| implementation 'com.squareup:javapoet:1.11.1' | ||
| implementation 'javax.annotation:javax.annotation-api:1.3.2' | ||
| implementation 'com.google.api:gax:1.50.1' |
There was a problem hiding this comment.
The effective version here for users will be the one from the main project (since it's shallower in the dependency hierarchy). We should just remove this (so we're on 1.60.1).
| @TaskAction | ||
| @Override | ||
| public void exec() { | ||
| if (!(exampleArguments?.trim())) { |
There was a problem hiding this comment.
We (sadly) need to support Java 8 which doesn't have the ? operator. Can you convert this to an explicit null check (sorry!)
There was a problem hiding this comment.
This is actually Groovy code, not Java. It compiles fine in Ubuntu with Java 8 as the only available JDK.
There was a problem hiding this comment.
If you specify javac -source 8 -target 8 does this still compile?
There was a problem hiding this comment.
I added a flag to target Java 1.8 compatibility of the output, just to be safe.
Not sure why would we use javac here?
|
|
||
| description = 'Google Ads API client library for Java examples' | ||
|
|
||
| public class ExampleRunnerTask extends JavaExec { |
There was a problem hiding this comment.
Could we move this to the buildSrc directory to simplify the build file here?
| main = basePackage + this.exampleArguments | ||
| } | ||
| // Otherwise, separate the input and set the arguments to pass to the main class. | ||
| else { |
There was a problem hiding this comment.
Please run google-java-format on the java code.
There was a problem hiding this comment.
This is actually Groovy code; I'll apply Java style to it though.
There was a problem hiding this comment.
Reformatted, please check.
nwbirnie
left a comment
There was a problem hiding this comment.
Couple of nits, otherwise LGTM. Nice job!
| task runMigrationExample(type: ExampleRunnerTask) { | ||
| classpath = sourceSets.main.runtimeClasspath | ||
| basePackage = 'com.google.ads.googleads.migration.' | ||
| } |
| testImplementation 'io.grpc:grpc-context:1.30.0' | ||
| testImplementation 'com.google.truth:truth:0.27' | ||
| testImplementation 'com.google.auto.value:auto-value-annotations:1.7.3' | ||
|
|
| @@ -0,0 +1,26 @@ | |||
| /* | |||
|
Friendly ping for @jradcliff :) |
jradcliff
left a comment
There was a problem hiding this comment.
By the way, on my Linux box:
- a
buildfrom scratch took just 2m59s - after that (with the daemon running),
clean buildtook 2s to 12s
That's quite an impressive improvement.

This is part of the effort to address long build times for the Java library, such as is raised in #346.