Skip to content

Commit

Permalink
Make it compatible with, and only with Gradle 2.12.
Browse files Browse the repository at this point in the history
The signature of a Gradle internal API that we use was changed in Gradle
2.12. Such change was not backward compatible, which it makes it very
hard for me to maintain backward compatibility with older Gradle
versions. I have to elevate the minimum required Gradle version to 2.12.

Related changes:
- Needs to upgrade Android plugin to 1.5.0 for it to work with Gradle
  2.12
- Switch away from deprecated Android plugin DSL.
  • Loading branch information
zhangkun83 committed Mar 15, 2016
1 parent 204010e commit 900c196
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.5'
classpath "com.gradle.publish:plugin-publish-plugin:0.9.0"
classpath 'junit:junit:4.7'
classpath 'org.jacoco:org.jacoco.core:0.7.4.201502262128'
}
}

Expand Down Expand Up @@ -70,7 +71,7 @@ dependencies {
}

task wrapper(type: Wrapper) {
gradleVersion = '2.4'
gradleVersion = '2.12'
}

task sourcesJar(type: Jar, dependsOn:classes) {
Expand Down
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 @@
#Tue Jan 26 11:26:58 PST 2016
#Tue Mar 15 12:35:16 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
10 changes: 3 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ case "`uname`" in
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
Expand All @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

Expand Down Expand Up @@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ class ProtobufPlugin implements Plugin<Project> {

@Inject
public ProtobufPlugin(FileResolver fileResolver) {
this.fileResolver = fileResolver;
this.fileResolver = fileResolver
}

void apply(final Project project) {
this.project = project
def gv = project.gradle.gradleVersion =~ "(\\d*)\\.(\\d*).*"
if (!gv || !gv.matches() || gv.group(1).toInteger() < 2 || gv.group(2).toInteger() < 4) {
println("You are using Gradle ${project.gradle.gradleVersion}: This version of the protobuf plugin requires minimum Gradle version 2.4")
if (!gv || !gv.matches() || gv.group(1).toInteger() != 2 || gv.group(2).toInteger() < 12) {
println("You are using Gradle ${project.gradle.gradleVersion}: "
+ " This version of the protobuf plugin works with Gradle version 2.12+")
}

// At least one of the prerequisite plugins must by applied before this plugin can be applied, so
Expand Down Expand Up @@ -146,7 +147,7 @@ class ProtobufPlugin implements Plugin<Project> {
*/
private addSourceSetExtensions() {
getSourceSets().all { sourceSet ->
sourceSet.extensions.create('proto', ProtobufSourceDirectorySet, project, sourceSet.name, fileResolver)
sourceSet.extensions.create('proto', ProtobufSourceDirectorySet, sourceSet.name, fileResolver)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.internal.file.DefaultSourceDirectorySet
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory
import org.gradle.internal.reflect.Instantiator
import org.gradle.util.ConfigureUtil

Expand All @@ -42,8 +43,8 @@ import org.gradle.util.ConfigureUtil
*/
public class ProtobufSourceDirectorySet extends DefaultSourceDirectorySet {

public ProtobufSourceDirectorySet(Project project, String name, FileResolver fileResolver) {
super(name, String.format("%s Proto source", name), fileResolver)
public ProtobufSourceDirectorySet(String name, FileResolver fileResolver) {
super(name, String.format("%s Proto source", name), fileResolver, new DefaultDirectoryFileTreeFactory())
srcDir("src/${name}/proto")
include("**/*.proto")
}
Expand Down
11 changes: 6 additions & 5 deletions testProjectAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ apply plugin: 'com.google.protobuf'

buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'junit:junit:4.7'
classpath 'org.jacoco:org.jacoco.core:0.7.4.201502262128'
}
}

Expand All @@ -24,16 +25,16 @@ android {
flavorDimensions 'abi', 'version'
productFlavors {
freeapp {
flavorDimension 'version'
dimension 'version'
}
retailapp {
flavorDimension 'version'
dimension 'version'
}
x86 {
flavorDimension 'abi'
dimension 'abi'
}
arm {
flavorDimension 'abi'
dimension 'abi'
}
}
buildTypes {
Expand Down

0 comments on commit 900c196

Please sign in to comment.