Skip to content

Commit

Permalink
Refactor Volley into a multi-module project. (#418)
Browse files Browse the repository at this point in the history
This splits the library into three Gradle modules:

- core - volley core + toolbox
- cronet - CronetHttpStack
- testing - common testing code

The primary purpose is to split out CronetHttpStack into its own Maven
artifact, com.android.volley:volley-cronet, to prevent applications
which aren't using it from having to either suppress Proguard/D8
warnings or pull in the unnecessary dependency.

The testing module is needed to share TestRequest between unit tests
in both core and cronet. It is not published to Maven.

This PR also removes support for the build.gradle/rules.gradle split
which allowed Gradle projects to depend on Volley by source and
specify their own SDK settings. This is no longer worth supporting,
and any client that wishes to depend on Volley via Gradle should do
so via published Maven artifacts instead.

See #412
  • Loading branch information
jpd236 committed Jul 7, 2021
1 parent 763c86b commit 0dc50bc
Show file tree
Hide file tree
Showing 110 changed files with 120 additions and 93 deletions.
104 changes: 50 additions & 54 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,76 +1,72 @@
// NOTE: The only changes that belong in this file are the definitions
// of tool versions (gradle plugin, compile SDK, build tools), so that
// Volley can be built via gradle as a standalone project.
//
// Any other changes to the build config belong in rules.gradle, which
// is used by projects that depend on Volley but define their own
// tools versions across all dependencies to ensure a consistent build.
//
// Most users should just add this line to settings.gradle:
// include(":volley")
//
// If you have a more complicated Gradle setup you can choose to use
// this instead:
// include(":volley")
// project(':volley').buildFileName = 'rules.gradle'

import net.ltgt.gradle.errorprone.CheckSeverity

buildscript {
repositories {
gradlePluginPortal()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6'
// NOTE: 0.7 or newer will require upgrading to a newer Android gradle plugin:
// https://github.com/tbroyer/gradle-errorprone-plugin/commit/65b1026ebeae1b7ed8c28578c7f6eea512c16bea
classpath 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:0.6.1'
}
}

plugins {
id "com.github.sherter.google-java-format" version "0.6"
// NOTE: 0.7 or newer will require upgrading to a newer Android gradle plugin:
// https://github.com/tbroyer/gradle-errorprone-plugin/commit/65b1026ebeae1b7ed8c28578c7f6eea512c16bea
id "net.ltgt.errorprone" version "0.6.1"
allprojects {
repositories {
jcenter()
google()
}
}

googleJavaFormat {
toolVersion = '1.5'
options style: 'AOSP'
}
subprojects {
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'net.ltgt.errorprone'

apply plugin: 'com.android.library'
googleJavaFormat {
toolVersion = '1.5'
options style: 'AOSP'
}

repositories {
jcenter()
google()
}
apply plugin: 'com.android.library'

dependencies {
// NOTE: Updating ErrorProne introduces new checks that may cause the build to fail. Pin to a
// specific version to control these updates.
errorprone("com.google.errorprone:error_prone_core:2.3.2")
// ErrorProne requires a JDK 9 compiler, so pull one in as a dependency since we use Java 8:
// https://github.com/tbroyer/gradle-errorprone-plugin#jdk-8-support
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
dependencies {
// NOTE: Updating ErrorProne introduces new checks that may cause the build to fail. Pin to a
// specific version to control these updates.
errorprone("com.google.errorprone:error_prone_core:2.3.2")
// ErrorProne requires a JDK 9 compiler, so pull one in as a dependency since we use Java 8:
// https://github.com/tbroyer/gradle-errorprone-plugin#jdk-8-support
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}

group = 'com.android.volley'
version = '1.2.1-SNAPSHOT'

android {
useLibrary 'org.apache.http.legacy'

group = 'com.android.volley'
version = '1.2.1-SNAPSHOT'
compileSdkVersion 28
buildToolsVersion = '28.0.3'

android {
compileSdkVersion 28
buildToolsVersion = '28.0.3'
defaultConfig {
minSdkVersion 8
}

defaultConfig {
minSdkVersion 8
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
}

tasks.withType(JavaCompile) {
options.errorprone {
check("ParameterComment", CheckSeverity.ERROR)
tasks.withType(JavaCompile) {
options.errorprone {
check("ParameterComment", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
}
options.compilerArgs << "-Xlint:unchecked" << "-Werror"
}
}

apply from: 'rules.gradle'
apply from: 'publish.gradle'
if (it.name != 'testing') {
apply from: '../publish.gradle'
}
}
28 changes: 28 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
android {
defaultConfig {
consumerProguardFiles 'consumer-proguard-rules.pro'
}
}

dependencies {
implementation "androidx.annotation:annotation:1.0.1"

testImplementation project(":testing")
testImplementation "junit:junit:4.12"
testImplementation "org.hamcrest:hamcrest-library:1.3"
testImplementation "org.mockito:mockito-core:2.19.0"
testImplementation "org.robolectric:robolectric:3.4.2"
}

publishing {
publications {
library(MavenPublication) {
artifactId 'volley'
pom {
name = 'Volley'
description = 'An HTTP library that makes networking for Android apps easier and, most importantly, faster.'
}
artifact "$buildDir/outputs/aar/core-release.aar"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions cronet/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dependencies {
implementation project(":core")
implementation "androidx.annotation:annotation:1.0.1"
compileOnly "org.chromium.net:cronet-embedded:76.3809.111"

testImplementation project(":testing")
testImplementation "org.chromium.net:cronet-embedded:76.3809.111"
testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:2.19.0"
testImplementation "org.robolectric:robolectric:3.4.2"
}

publishing {
publications {
library(MavenPublication) {
artifactId 'volley-cronet'
pom {
name = 'Volley Cronet'
description = 'Cronet support for Volley.'
}
artifact "$buildDir/outputs/aar/cronet-release.aar"
}
}
}
2 changes: 2 additions & 0 deletions cronet/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.android.volley.cronet" />
9 changes: 6 additions & 3 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ task javadoc(type: Javadoc) {
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant ->
variant.getJavaCompile().classpath.files
})
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
Expand All @@ -24,11 +30,9 @@ publishing {
publications {
library(MavenPublication) {
groupId 'com.android.volley'
artifactId 'volley'
version project.version
pom {
name = 'Volley'
description = 'An HTTP library that makes networking for Android apps easier and, most importantly, faster.'
url = 'https://github.com/google/volley'
packaging 'aar'
licenses {
Expand All @@ -51,7 +55,6 @@ publishing {
}

// Release AAR, Sources, and JavaDoc
artifact "$buildDir/outputs/aar/volley-release.aar"
artifact sourcesJar
artifact javadocJar
}
Expand Down
36 changes: 0 additions & 36 deletions rules.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rootProject.name = 'volley'
include 'core'
include 'cronet'
include 'testing'
4 changes: 4 additions & 0 deletions testing/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation project(":core")
}

2 changes: 2 additions & 0 deletions testing/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.android.volley.testing" />

0 comments on commit 0dc50bc

Please sign in to comment.