Skip to content

Commit

Permalink
Make okbuck Java 11 Compatible (#921)
Browse files Browse the repository at this point in the history
* Add java 11 testing bits in travis

* Update commandline sdk tools

* Update commandline sdk tools

* Update commandline sdk tools

* Java 11 compatibility changes

* Fix build

* Add java 11 handling for downloading buck

* Add annotation deps to fix build
  • Loading branch information
kageiit authored Jul 20, 2020
1 parent dcbc9ae commit 53fa269
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 27 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: java
jdk:
- openjdk8
- openjdk11

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down Expand Up @@ -36,14 +37,14 @@ install:
- python --version
- mkdir -p $HOME/android-sdk-dl
- mkdir -p $HOME/android-sdk
- curl https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip > $HOME/android-sdk-dl/sdk-tools.zip
- unzip -qq -n $HOME/android-sdk-dl/sdk-tools.zip -d $HOME/android-sdk
- curl https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip > $HOME/android-sdk-dl/sdk-tools.zip
- unzip -qq -n $HOME/android-sdk-dl/sdk-tools.zip -d $HOME/android-sdk/cmdline-tools

- yes | $HOME/android-sdk/tools/bin/sdkmanager --licenses
- yes | $HOME/android-sdk/cmdline-tools/tools/bin/sdkmanager --licenses

- $HOME/android-sdk/tools/bin/sdkmanager 'platform-tools' > /dev/null
- $HOME/android-sdk/tools/bin/sdkmanager 'build-tools;30.0.0' > /dev/null
- $HOME/android-sdk/tools/bin/sdkmanager 'platforms;android-29' > /dev/null
- $HOME/android-sdk/cmdline-tools/tools/bin/sdkmanager 'platform-tools' > /dev/null
- $HOME/android-sdk/cmdline-tools/tools/bin/sdkmanager 'build-tools;30.0.0' > /dev/null
- $HOME/android-sdk/cmdline-tools/tools/bin/sdkmanager 'platforms;android-29' > /dev/null

script:
- ./tooling/ci/build_cmd.sh
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ repositories {

dependencies {
compileOnly deps.apt.autoValueAnnotations
compileOnly deps.external.annotationApi

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation(name: "rxscreenshotdetector-1.2.0", ext: "aar")
Expand Down
5 changes: 3 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jar {
}

tasks.withType(JavaCompile) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets.main.java.srcDirs = ["src/main/rocker", "src/main/java"]
Expand All @@ -45,6 +45,7 @@ dependencies {

compileOnly deps.external.inferAnnotations
compileOnly deps.apt.autoValueAnnotations
compileOnly deps.external.annotationApi

implementation gradleApi()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.uber.okbuck.core.dependency.DependencyFactory;
import com.uber.okbuck.core.manager.BuckFileManager;
import com.uber.okbuck.core.manager.BuckManager;
import com.uber.okbuck.core.manager.D8Manager;
import com.uber.okbuck.core.manager.DependencyManager;
import com.uber.okbuck.core.manager.GroovyManager;
import com.uber.okbuck.core.manager.JetifierManager;
Expand All @@ -19,7 +20,6 @@
import com.uber.okbuck.core.model.base.ProjectType;
import com.uber.okbuck.core.task.OkBuckCleanTask;
import com.uber.okbuck.core.task.OkBuckTask;
import com.uber.okbuck.core.util.D8Util;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.MoreCollectors;
import com.uber.okbuck.core.util.ProjectCache;
Expand Down Expand Up @@ -109,6 +109,7 @@ public class OkBuckGradlePlugin implements Plugin<Project> {
public GroovyManager groovyManager;
public JetifierManager jetifierManager;
public TransformManager transformManager;
public D8Manager d8Manager;

ManifestMergerManager manifestMergerManager;
RobolectricManager robolectricManager;
Expand Down Expand Up @@ -176,6 +177,9 @@ public void apply(Project rootProject) {
// Create Transform Manager
transformManager = new TransformManager(rootBuckProject, buckFileManager);

// Create D8 Manager
d8Manager = new D8Manager(rootBuckProject);

// Create Buck Manager
buckManager = new BuckManager(rootBuckProject);

Expand Down Expand Up @@ -276,7 +280,7 @@ public void apply(Project rootProject) {
}

// Setup d8 deps
D8Util.copyDeps(buckFileManager);
d8Manager.copyDeps(buckFileManager);

// Fetch robolectric deps if needed
if (okbuckExt.getTestExtension().robolectric) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.core.model.base.SourceSetType;
import com.uber.okbuck.core.model.jvm.JvmTarget;
import com.uber.okbuck.core.util.D8Util;
import com.uber.okbuck.core.manager.D8Manager;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.ProjectUtil;
import com.uber.okbuck.template.android.AndroidRule;
Expand Down Expand Up @@ -44,7 +44,7 @@ public static Rule compose(
Set<String> providedDeps = new HashSet<>();
providedDeps.addAll(external(target.getExternalProvidedDeps(SourceSetType.MAIN)));
providedDeps.addAll(targets(target.getTargetProvidedDeps(SourceSetType.MAIN)));
providedDeps.add(D8Util.RT_STUB_JAR_RULE);
providedDeps.add(D8Manager.RT_STUB_JAR_RULE);

Set<String> libraryExportedDeps = new HashSet<>();
libraryExportedDeps.addAll(external(target.getExternalExportedDeps(SourceSetType.MAIN)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.core.model.base.SourceSetType;
import com.uber.okbuck.core.model.jvm.JvmTarget;
import com.uber.okbuck.core.util.D8Util;
import com.uber.okbuck.core.manager.D8Manager;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.ProjectUtil;
import com.uber.okbuck.template.android.AndroidModuleRule;
Expand Down Expand Up @@ -43,7 +43,7 @@ public static Rule compose(
Set<String> providedDeps = new HashSet<>();
providedDeps.addAll(external(target.getExternalProvidedDeps(SourceSetType.MAIN)));
providedDeps.addAll(targets(target.getTargetProvidedDeps(SourceSetType.MAIN)));
providedDeps.add(D8Util.RT_STUB_JAR_RULE);
providedDeps.add(D8Manager.RT_STUB_JAR_RULE);

Set<String> libraryExportedDeps = new HashSet<>();
libraryExportedDeps.addAll(external(target.getExternalExportedDeps(SourceSetType.MAIN)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.uber.okbuck.core.model.android.AndroidLibTarget;
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.core.model.base.SourceSetType;
import com.uber.okbuck.core.util.D8Util;
import com.uber.okbuck.core.manager.D8Manager;
import com.uber.okbuck.template.android.AndroidTestRule;
import com.uber.okbuck.template.core.Rule;
import java.util.ArrayList;
Expand Down Expand Up @@ -42,7 +42,7 @@ public static Rule compose(
Set<String> providedDeps = new LinkedHashSet<>();
providedDeps.addAll(external(target.getExternalProvidedDeps(SourceSetType.TEST)));
providedDeps.addAll(targets(target.getTargetProvidedDeps(SourceSetType.TEST)));
providedDeps.add(D8Util.RT_STUB_JAR_RULE);
providedDeps.add(D8Manager.RT_STUB_JAR_RULE);

AndroidTestRule androidTest =
new AndroidTestRule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.uber.okbuck.core.model.android.ExoPackageScope;
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.core.model.base.SourceSetType;
import com.uber.okbuck.core.util.D8Util;
import com.uber.okbuck.core.manager.D8Manager;
import com.uber.okbuck.template.android.AndroidRule;
import com.uber.okbuck.template.core.Rule;
import java.util.ArrayList;
Expand Down Expand Up @@ -38,7 +38,7 @@ public static Rule compose(AndroidAppTarget target) {
libraryAptDeps.addAll(targetsApt(target.getTargetAptDeps(SourceSetType.MAIN)));

Set<String> providedDeps = new LinkedHashSet<>();
providedDeps.add(D8Util.RT_STUB_JAR_RULE);
providedDeps.add(D8Manager.RT_STUB_JAR_RULE);

AndroidRule androidRule =
new AndroidRule()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uber.okbuck.core.manager;

import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Var;
import com.uber.okbuck.OkBuckGradlePlugin;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.ProjectUtil;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void setupBuckBinary() {
rootProject
.getRepositories()
.maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(JITPACK_URL));
rootProject.getDependencies().add(BUCK_BINARY_CONFIGURATION, okbuckExt.buckBinary);
rootProject.getDependencies().add(BUCK_BINARY_CONFIGURATION, getJavaVersion() == 11 ? okbuckExt.buckBinaryJava11 : okbuckExt.buckBinary);

Set<File> resolvedFiles = buckConfig.getResolvedConfiguration().getFiles();
Preconditions.checkArgument(resolvedFiles.size() == 1);
Expand All @@ -60,4 +61,15 @@ public void finalizeDependencies() {
FileUtil.symlink(linkedBinaryPath, realBuckBinaryPath);
}
}

private static int getJavaVersion() {
@Var String version = System.getProperty("java.version");
if(version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if(dot != -1) { version = version.substring(0, dot); }
}
return Integer.parseInt(version);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.uber.okbuck.core.util;
package com.uber.okbuck.core.manager;

import com.uber.okbuck.OkBuckGradlePlugin;
import com.uber.okbuck.core.manager.BuckFileManager;
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.template.core.Rule;
import com.uber.okbuck.template.java.NativePrebuilt;
import com.uber.okbuck.core.util.FileUtil;
import java.io.File;
import java.util.Collections;
import java.util.List;
import org.gradle.api.Project;

public final class D8Util {
public final class D8Manager {

private static final String D8_CACHE = OkBuckGradlePlugin.WORKSPACE_PATH + "/d8";
private static final String RT_STUB_JAR = "rt-stub.jar";
public static final String RT_STUB_JAR_RULE = "//" + D8_CACHE + ":" + RT_STUB_JAR;

private D8Util() {}
private final Project rootProject;

public static void copyDeps(BuckFileManager buckFileManager) {
FileUtil.copyResourceToProject("d8/" + RT_STUB_JAR, new File(D8_CACHE, RT_STUB_JAR));
public D8Manager(Project rootProject) {
this.rootProject = rootProject;
}

public void copyDeps(BuckFileManager buckFileManager) {
FileUtil.copyResourceToProject("d8/" + RT_STUB_JAR, rootProject.file(D8_CACHE + File.separator + RT_STUB_JAR));

List<Rule> d8 =
Collections.singletonList(
Expand All @@ -28,6 +34,6 @@ public static void copyDeps(BuckFileManager buckFileManager) {
.ruleType(RuleType.PREBUILT_JAR.getBuckName())
.name(RT_STUB_JAR));

buckFileManager.writeToBuckFile(d8, new File(D8_CACHE, OkBuckGradlePlugin.BUCK));
buckFileManager.writeToBuckFile(d8, rootProject.file(D8_CACHE + File.separator + OkBuckGradlePlugin.BUCK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@SuppressWarnings("unused")
public class OkBuckExtension {

private static final String DEFAULT_BUCK_BINARY_SHA = "0299f0ff54201b700c06f8892862e1109d9739eb";

/** Build Tools Version */
@Input public String buildToolVersion = "28.0.2";

Expand Down Expand Up @@ -83,7 +85,12 @@ public class OkBuckExtension {
/** The prebuilt buck binary to use */
@Input
public String buckBinary =
"com.github.facebook:buck:0aeb8be606590c8203827a20dfa3c7f14a12fb5d@pex";
"com.github.facebook:buck:" + DEFAULT_BUCK_BINARY_SHA + "@pex";

/** The prebuilt buck binary to use with java 11 */
@Input
public String buckBinaryJava11 =
"com.github.facebook:buck:" + DEFAULT_BUCK_BINARY_SHA + ":java11@pex";

private WrapperExtension wrapperExtension = new WrapperExtension();
private KotlinExtension kotlinExtension;
Expand Down
3 changes: 2 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def versions = [
autovalue : "1.7.4",
avro : "1.10.0",
butterKnife : "10.2.1",
dagger : "2.28.2",
dagger : "2.28.3",
jna : "5.6.0",
kotlin : "1.3.72",
leakCanary : "1.5.4",
Expand Down Expand Up @@ -78,6 +78,7 @@ def apt = [
]

def external = [
annotationApi : ["javax.annotation:javax.annotation-api:1.3.2", "com.github.pengrad:jdk9-deps:1.0"],
butterKnife : "com.jakewharton:butterknife:${versions.butterKnife}",
dagger : "com.google.dagger:dagger:${versions.dagger}",
daggerAndroid : "com.google.dagger:dagger-android-support:${versions.dagger}",
Expand Down
2 changes: 2 additions & 0 deletions dummylibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ android {
}

dependencies {
compileOnly deps.external.annotationApi

api deps.external.dagger
api deps.external.gson

Expand Down
2 changes: 2 additions & 0 deletions java-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: "java-library"
apply plugin: "application"

dependencies {
compileOnly deps.external.annotationApi

implementation deps.external.gson
implementation deps.external.dagger
implementation deps.external.avroIpc
Expand Down
4 changes: 4 additions & 0 deletions kotlin-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ dependencies {
kapt deps.apt.autoValueGson

compileOnly deps.apt.autoValueAnnotations
compileOnly deps.external.annotationApi

kaptTest deps.apt.daggerCompiler

testCompileOnly deps.external.annotationApi
androidTestCompileOnly deps.external.annotationApi

kaptAndroidTest deps.apt.daggerCompiler
kaptAndroidTest deps.apt.daggerAndroidProcessor

Expand Down
2 changes: 2 additions & 0 deletions libraries/javalibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ integrationTest {
}

dependencies {
compileOnly deps.external.annotationApi

api deps.external.gson
implementation deps.external.dagger

Expand Down
3 changes: 3 additions & 0 deletions libraries/kotlinlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ apply plugin: "kotlin-kapt"
apply plugin: "kotlin-allopen"

dependencies {
compileOnly deps.external.annotationApi
testCompileOnly deps.external.annotationApi

implementation deps.external.kotlinStdlib
implementation deps.external.dagger
kapt deps.apt.daggerCompiler
Expand Down
1 change: 1 addition & 0 deletions libraries/lintErrorLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: "com.android.library"
apply plugin: "com.jakewharton.butterknife"

dependencies {
compileOnly deps.external.annotationApi
buckLint project (":libraries:customLintLibrary")

annotationProcessor deps.apt.butterKnifeCompiler
Expand Down

0 comments on commit 53fa269

Please sign in to comment.