Skip to content

Commit

Permalink
Partial move to gradle kotlin (#6532)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Feb 6, 2021
1 parent 6e8aa12 commit b607bb0
Show file tree
Hide file tree
Showing 34 changed files with 387 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[*.kt]
[{*.kt, *.kts}]
indent_size = 2
155 changes: 9 additions & 146 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,68 +1,9 @@
buildscript {
ext.versions = [
'animalSniffer': '1.19',
'assertj': '3.15.0',
'bouncycastle': '1.67',
'brotli': '0.1.2',
'checkstyle': '8.28',
'conscrypt': '2.5.1',
'corretto': '1.3.1',
'findbugs': '3.0.2',
'guava': '28.2-jre',
'java': '1.8',
'jnrUnixsocket': '0.28',
'jsoup': '1.13.1',
'junit': '4.13',
'junit5': '5.7.0',
'kotlin': '1.4.30',
'moshi': '1.11.0',
'okio': '3.0.0-alpha.1',
'ktlint': '0.38.0',
'picocli': '4.5.1',
'openjsse': '1.1.0',
'bnd': '5.1.2',
'equinox': '3.16.0'
]

ext.deps = [
'picocli': "info.picocli:picocli:${versions.picocli}",
'android': "org.robolectric:android-all:11-robolectric-6757853",
'animalSniffer': "org.codehaus.mojo:animal-sniffer-annotations:${versions.animalSniffer}",
'assertj': "org.assertj:assertj-core:${versions.assertj}",
'bouncycastle': "org.bouncycastle:bcprov-jdk15to18:${versions.bouncycastle}",
'bouncycastlepkix': "org.bouncycastle:bcpkix-jdk15to18:${versions.bouncycastle}",
'bouncycastletls': "org.bouncycastle:bctls-jdk15to18:${versions.bouncycastle}",
'brotli': "org.brotli:dec:${versions.brotli}",
'conscrypt': "org.conscrypt:conscrypt-openjdk-uber:${versions.conscrypt}",
'corretto': "software.amazon.cryptools:AmazonCorrettoCryptoProvider:${versions.corretto}:linux-x86_64",
'guava': "com.google.guava:guava:${versions.guava}",
'hamcrest': 'org.hamcrest:hamcrest-library:2.1',
'jnrUnixsocket': "com.github.jnr:jnr-unixsocket:${versions.jnrUnixsocket}",
'jsoup': "org.jsoup:jsoup:${versions.jsoup}",
'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}",
'junit': "junit:junit:${versions.junit}",
'junit5Api': "org.junit.jupiter:junit-jupiter-api:${versions.junit5}",
'junit5JupiterEngine': "org.junit.jupiter:junit-jupiter-engine:${versions.junit5}",
'junit5JupiterParams': "org.junit.jupiter:junit-jupiter-params:${versions.junit5}",
'junit5VintageEngine': "org.junit.vintage:junit-vintage-engine:${versions.junit5}",
'junitPlatformConsole': "org.junit.platform:junit-platform-console:1.7.0",
'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}",
'moshi': "com.squareup.moshi:moshi:${versions.moshi}",
'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}",
'okio': "com.squareup.okio:okio:${versions.okio}",
'okioFakeFileSystem': "com.squareup.okio:okio-fakefilesystem:${versions.okio}",
'openjsse': "org.openjsse:openjsse:${versions.openjsse}",
'bnd': "biz.aQute.bnd:biz.aQute.bnd.gradle:${versions.bnd}",
'bndResolve': "biz.aQute.bnd:biz.aQute.resolve:${versions.bnd}",
'equinox': "org.eclipse.platform:org.eclipse.osgi:${versions.equinox}",
'kotlinStdlibOsgi': "org.jetbrains.kotlin:kotlin-osgi-bundle:${versions.kotlin}"
]

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1"
classpath "com.android.tools.build:gradle:4.0.2"
classpath deps.bnd
classpath Dependencies.bnd
}

repositories {
Expand All @@ -80,35 +21,9 @@ plugins {
id "net.ltgt.errorprone" version "1.2.1"
}

/** Returns the artifact ID for the project, or null if it is not published. */
ext.publishedArtifactId = { project ->
if (project.name == 'okhttp-logging-interceptor') {
return 'logging-interceptor'
} else if (project.name == 'mockwebserver') {
return 'mockwebserver3'
} else if (project.name == 'mockwebserver-junit4') {
return 'mockwebserver3-junit4'
} else if (project.name == 'mockwebserver-junit5') {
return 'mockwebserver3-junit5'
} else if (project.name == 'mockwebserver-deprecated') {
return 'mockwebserver'
} else if (project.name == 'okcurl'
|| project.name == 'okhttp'
|| project.name == 'okhttp-bom'
|| project.name == 'okhttp-brotli'
|| project.name == 'okhttp-dnsoverhttps'
|| project.name == 'okhttp-sse'
|| project.name == 'okhttp-tls'
|| project.name == 'okhttp-urlconnection') {
return project.name
} else {
return null // Not published.
}
}

allprojects {
group = 'com.squareup.okhttp3'
project.ext.artifactId = rootProject.ext.publishedArtifactId(project)
project.ext.artifactId = Projects.publishedArtifactId(project.name)
version = '5.0.0-SNAPSHOT'

repositories {
Expand Down Expand Up @@ -139,7 +54,7 @@ ext.applyOsgi = { project ->

project.dependencies {
// The OSGi kotlin-stdlib lets bnd infer bundle versions.
osgiApi deps.kotlinStdlibOsgi
osgiApi Dependencies.kotlinStdlibOsgi
}
}

Expand Down Expand Up @@ -173,14 +88,14 @@ subprojects { project ->
checkstyleConfig
}
dependencies {
checkstyleConfig dependencies.create("com.puppycrawl.tools:checkstyle:${versions.checkstyle}") {
checkstyleConfig dependencies.create("com.puppycrawl.tools:checkstyle:${Versions.checkstyle}") {
transitive = false
}
}
afterEvaluate {
checkstyle {
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
toolVersion "${versions.checkstyle}"
toolVersion "${Versions.checkstyle}"
sourceSets = [project.sourceSets.main]
}
}
Expand All @@ -205,8 +120,8 @@ subprojects { project ->
def testJavaVersion = Integer.getInteger("test.java.version", 11)

dependencies {
testRuntimeOnly(deps.junit5JupiterEngine)
testRuntimeOnly(deps.junit5VintageEngine)
testRuntimeOnly(Dependencies.junit5JupiterEngine)
testRuntimeOnly(Dependencies.junit5VintageEngine)
}

test {
Expand All @@ -229,7 +144,7 @@ subprojects { project ->

if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
def alpnBootVersion = alpnBootVersion()
def alpnBootVersion = Alpn.alpnBootVersion()
if (alpnBootVersion != null) {
def alpnBootJar = configurations.detachedConfiguration(
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")).singleFile
Expand All @@ -243,7 +158,7 @@ subprojects { project ->
}
} else if (platform == "openjsse") {
dependencies {
testRuntime deps.openjsse
testRuntime Dependencies.openjsse
}
}

Expand Down Expand Up @@ -348,58 +263,6 @@ tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}

/**
* Returns the alpn-boot version specific to this OpenJDK 8 JVM, or null if this is not a Java 8 VM.
* https://github.com/xjdr/xio/blob/master/alpn-boot.gradle
*/
def alpnBootVersion() {
def version = System.getProperty('alpn.boot.version')

if (version != null) {
return version
}

def javaVersion = System.getProperty("java.version")
def patchVersionMatcher = (javaVersion =~ /1\.8\.0_(\d+)(-.*)?/)
if (!patchVersionMatcher.find()) return null
def patchVersion = Integer.parseInt(patchVersionMatcher.group(1))
return alpnBootVersionForPatchVersion(javaVersion, patchVersion)
}

static def alpnBootVersionForPatchVersion(String javaVersion, int patchVersion) {
// https://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions
switch (patchVersion) {
case 0..24:
return '8.1.0.v20141016'
case 25..30:
return '8.1.2.v20141202'
case 31..50:
return '8.1.3.v20150130'
case 51..59:
return '8.1.4.v20150727'
case 60..64:
return '8.1.5.v20150921'
case 65..70:
return '8.1.6.v20151105'
case 71..77:
return '8.1.7.v20160121'
case 78..101:
return '8.1.8.v20160420'
case 102..111:
return '8.1.9.v20160720'
case 112..120:
return '8.1.10.v20161026'
case 121..160:
return '8.1.11.v20170118'
case 161..181:
return '8.1.12.v20180117'
case 191..242:
return '8.1.13.v20181017'
default:
throw new IllegalStateException("Unexpected Java version: ${javaVersion}")
}
}

/**
* Returns a .jar file for the golden version of this project.
* https://github.com/Visistema/Groovy1/blob/ba5eb9b2f19ca0cc8927359ce414c4e1974b7016/gradle/binarycompatibility.gradle#L48
Expand Down
27 changes: 27 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
`kotlin-dsl`
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}

repositories {
mavenCentral()
}
55 changes: 55 additions & 0 deletions buildSrc/src/main/kotlin/alpn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

object Alpn {
// https://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions
fun alpnBootVersionForPatchVersion(patchVersion: Int): String? {
return when (patchVersion) {
in 0..24 -> "8.1.0.v20141016"
in 25..30 -> "8.1.2.v20141202"
in 31..50 -> "8.1.3.v20150130"
in 51..59 -> "8.1.4.v20150727"
in 60..64 -> "8.1.5.v20150921"
in 65..70 -> "8.1.6.v20151105"
in 71..77 -> "8.1.7.v20160121"
in 78..101 -> "8.1.8.v20160420"
in 102..111 -> "8.1.9.v20160720"
in 112..120 -> "8.1.10.v20161026"
in 121..160 -> "8.1.11.v20170118"
in 161..181 -> "8.1.12.v20180117"
in 191..242 -> "8.1.13.v20181017"
else -> null
}
}

/**
* Returns the alpn-boot version specific to this OpenJDK 8 JVM, or null if this is not a Java 8 VM.
* https://github.com/xjdr/xio/blob/master/alpn-boot.gradle
*/
@JvmStatic
fun alpnBootVersion(): String? {
val version = System.getProperty("alpn.boot.version")

if (version != null) {
return version
}

val javaVersion = System.getProperty("java.version")
val match = "1\\.8\\.0_(\\d+)(-.*)?".toRegex().find(javaVersion) ?: return null

return alpnBootVersionForPatchVersion(match.groupValues.first().toInt())
}
}
38 changes: 38 additions & 0 deletions buildSrc/src/main/kotlin/artifacts.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

object Projects {
/** Returns the artifact ID for the project, or null if it is not published. */
@JvmStatic
fun publishedArtifactId(projectName: String): String? {
return when (projectName) {
"okhttp-logging-interceptor" -> "logging-interceptor"
"mockwebserver" -> "mockwebserver3"
"mockwebserver-junit4" -> "mockwebserver3-junit4"
"mockwebserver-junit5" -> "mockwebserver3-junit5"
"mockwebserver-deprecated" -> "mockwebserver"
"okcurl",
"okhttp",
"okhttp-bom",
"okhttp-brotli",
"okhttp-dnsoverhttps",
"okhttp-sse",
"okhttp-tls",
"okhttp-urlconnection" -> projectName
else -> null
}
}
}

0 comments on commit b607bb0

Please sign in to comment.