Skip to content

Commit

Permalink
Fix compile task depends (GoogleCloudPlatform#49)
Browse files Browse the repository at this point in the history
* upgrade to gradle 4.0

* Fix generated source for non-java jvm languages

Generated source was not being recognized by non-java languages
(like kotlin) because
1. Source generation wasn't configured to explicitly happen before
any compile task except the java one. Potentially other languages
could initiate a compile without having first triggered source
generation.
2. Configuring the java sourceSet happened too late (after
evaluation) and other language plugins weren't being configured
with our sourceSet modifications.
  • Loading branch information
loosebazooka authored Aug 11, 2017
1 parent 4c78444 commit 0c16ca8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Discovery documents will be written to `build/endpointsDiscoveryDocs`
In your client Java app, add the following plugin to your build.gradle:

```Groovy
// apply this plugin after you have applied other plugins
// because it uses the state of other plugins
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
```

Expand All @@ -72,7 +74,8 @@ The plugin exposes intermodule endpoints configuration through a custom dependen
* `endpointsServer` - Configure generation of source from another module in the project

#### Usage (from discovery docs)
In your build.gradle define the location of the discovery document
In your build.gradle define the location of the discovery document in the
`endpointsClient` configuration closure.

```Groovy
endpointsClient {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ jar {
}

task wrapper(type: Wrapper) {
gradleVersion = '3.4.1'
gradleVersion = '4.0'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 26 14:12:21 EDT 2017
#Thu Jun 29 14:10:01 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
19 changes: 11 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.compile.AbstractCompile;

/**
* Plugin definition for Endpoints Clients. All tasks from this plugin are internal, it will
Expand Down Expand Up @@ -201,33 +201,26 @@ public void execute(Project project) {
});

if (project.getExtensions().findByName("android") != null) {
// special handling for android is done in groovy by the android specific plugin
project.apply(
ImmutableMap.of("plugin", "com.google.cloud.tools.endpoints-framework-android-client"));
} else {
// this is for standard java applications
// since we are generating sources add the gen-src directory to the main java sourceset
project.afterEvaluate(
new Action<Project>() {
@Override
public void execute(final Project project) {
project
.getTasks()
.withType(
JavaCompile.class,
new Action<JavaCompile>() {
@Override
public void execute(JavaCompile javaCompile) {
javaCompile.dependsOn(GENERATE_CLIENT_LIBRARY_SRC_TASK);
}
});

JavaPluginConvention java =
project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSetContainer sourceSets = java.getSourceSets();
SourceSet mainSrc = sourceSets.getByName("main");
mainSrc.getJava().srcDir(extension.getGenSrcDir());
}
});
project
.getTasks()
.withType(
AbstractCompile.class,
new Action<AbstractCompile>() {
@Override
public void execute(AbstractCompile compile) {
compile.dependsOn(GENERATE_CLIENT_LIBRARY_SRC_TASK);
}
});
JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSetContainer sourceSets = java.getSourceSets();
SourceSet mainSrc = sourceSets.getByName("main");
mainSrc.getJava().srcDir(extension.getGenSrcDir());
}
}
}

0 comments on commit 0c16ca8

Please sign in to comment.