Skip to content

Commit 0078fca

Browse files
Egor Andreevichswankjesse
Egor Andreevich
authored andcommitted
Kotlin Gradle MPP 1.3 (#544)
* Basic setup * Ignore failing test * Gradle 5.0 * Better native config * Fix jvm tests * JS testing setup * Native config * Use EAP dependencies * Japicmp setup * Correct path to japicmp report * Basic JVM + AnimalSniffer setup * Enable samples module * Use jvmWithJava for running Java tests * Include more Native platforms to force test task generation * Use internal UTF-8 decoder for Kotlin/Native * Kotlin 1.3.20 * Gradle 5.1 * Move JMH setup into a separate module * Properly configure jmhJar task * Remove old jvm build.gradle * Replace publishing plugin with SQLDelight's custom script * Use default artifactId for JVM target * Revert JVM build.gradle rename, use new DSL for defining targets * Remove old module definitions in settings * Feedback fixes
1 parent d1bc009 commit 0078fca

35 files changed

+450
-234
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ after_success:
1515
- .buildscript/deploy_snapshot.sh
1616

1717
after_failure:
18-
- cat okio/jvm/build/reports/japi.txt
18+
- cat okio/jvm/japicmp/build/reports/japi.txt
1919

2020
env:
2121
global:

build.gradle

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
buildscript {
22
ext.versions = [
3-
'kotlin': '1.2.60',
4-
'kotlinNative': '0.8.2',
5-
'jmhPlugin': '0.4.5',
6-
'animalSnifferPlugin': '1.4.3',
3+
'kotlin': '1.3.20',
4+
'jmhPlugin': '0.4.8',
5+
'animalSnifferPlugin': '1.4.6',
76
'dokka': '0.9.16',
8-
'jmh': '1.20',
7+
'jmh': '1.21',
98
'animalSniffer': '1.16',
109
'junit': '4.12',
1110
'assertj': '1.7.0',
12-
'shadowPlugin': '2.0.2',
11+
'shadowPlugin': '4.0.4',
1312
'nodePlugin': '1.2.0',
14-
'mavenPublishPlugin': '0.4.0',
1513
'ktlintPlugin': '5.1.0',
1614
]
1715

@@ -31,9 +29,6 @@ buildscript {
3129
'jdk': "org.jetbrains.kotlin:kotlin-test-junit",
3230
'js': "org.jetbrains.kotlin:kotlin-test-js",
3331
],
34-
'native': [
35-
'gradlePlugin': "org.jetbrains.kotlin:kotlin-native-gradle-plugin:${versions.kotlinNative}",
36-
]
3732
],
3833
'jmh': [
3934
'gradlePlugin': "me.champeau.gradle:jmh-gradle-plugin:${versions.jmhPlugin}",
@@ -48,7 +43,6 @@ buildscript {
4843
'dokka': "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}",
4944
'shadow': "com.github.jengelman.gradle.plugins:shadow:${versions.shadowPlugin}",
5045
'node': "com.moowork.gradle:gradle-node-plugin:${versions.nodePlugin}",
51-
'mavenPublish': "com.vanniktech:gradle-maven-publish-plugin:${versions.mavenPublishPlugin}",
5246
'ktlint': "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:${versions.ktlintPlugin}",
5347
'test': [
5448
'junit': "junit:junit:${versions.junit}",
@@ -58,14 +52,12 @@ buildscript {
5852

5953
dependencies {
6054
classpath deps.kotlin.gradlePlugin
61-
classpath deps.kotlin.native.gradlePlugin
6255
classpath deps.animalSniffer.gradlePlugin
6356
classpath deps.japicmp
6457
classpath deps.dokka
6558
classpath deps.shadow
6659
classpath deps.jmh.gradlePlugin
6760
classpath deps.node
68-
classpath deps.mavenPublish
6961
classpath deps.ktlint
7062
}
7163

gradle/gradle-mvn-mpp-push.gradle

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
apply plugin: 'org.jetbrains.dokka'
4+
5+
dokka {
6+
impliedPlatforms = ["Common"] // This will force platform tags for all non-common sources e.g. "JVM"
7+
kotlinTasks {
8+
// dokka fails to retrieve sources from MPP-tasks so they must be set empty to avoid exception
9+
// use sourceRoot instead (see below)
10+
[]
11+
}
12+
packageOptions {
13+
prefix = "com.squareup.okio"
14+
suppress = true
15+
}
16+
sourceRoot {
17+
// assuming there is only a single source dir...
18+
path = kotlin.sourceSets.commonMain.kotlin.srcDirs[0]
19+
platforms = ["Common"]
20+
}
21+
if (kotlin.sourceSets.getNames().contains("jvmMain")) {
22+
sourceRoot {
23+
// assuming there is only a single source dir...
24+
path = kotlin.sourceSets.jvmMain.kotlin.srcDirs[0]
25+
platforms = ["JVM"]
26+
}
27+
}
28+
if (kotlin.sourceSets.getNames().contains("jsMain")) {
29+
sourceRoot {
30+
// assuming there is only a single source dir...
31+
path = kotlin.sourceSets.jsMain.kotlin.srcDirs[0]
32+
platforms = ["js"]
33+
}
34+
}
35+
if (kotlin.sourceSets.getNames().contains("nativeMain")) {
36+
sourceRoot {
37+
// assuming there is only a single source dir...
38+
path = kotlin.sourceSets.nativeMain.kotlin.srcDirs[0]
39+
platforms = ["native"]
40+
}
41+
}
42+
}
43+
44+
def isReleaseBuild() {
45+
return VERSION_NAME.contains("SNAPSHOT") == false
46+
}
47+
48+
def getReleaseRepositoryUrl() {
49+
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL :
50+
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
51+
}
52+
53+
def getSnapshotRepositoryUrl() {
54+
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL :
55+
"https://oss.sonatype.org/content/repositories/snapshots/"
56+
}
57+
58+
def getRepositoryUsername() {
59+
return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
60+
}
61+
62+
def getRepositoryPassword() {
63+
return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
64+
}
65+
66+
task emptySourcesJar(type: Jar) {
67+
classifier = 'sources'
68+
}
69+
70+
task javadocsJar(type: Jar, dependsOn: dokka) {
71+
classifier = 'javadoc'
72+
from dokka.outputDirectory
73+
}
74+
75+
signing {
76+
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
77+
sign(publishing.publications)
78+
}
79+
80+
publishing {
81+
publications.all {
82+
artifact javadocsJar
83+
84+
pom.withXml {
85+
def root = asNode()
86+
87+
root.children().last() + {
88+
resolveStrategy = Closure.DELEGATE_FIRST
89+
90+
description POM_DESCRIPTION
91+
name POM_NAME
92+
url POM_URL
93+
licenses {
94+
license {
95+
name POM_LICENCE_NAME
96+
url POM_LICENCE_URL
97+
distribution POM_LICENCE_DIST
98+
}
99+
}
100+
scm {
101+
url POM_SCM_URL
102+
connection POM_SCM_CONNECTION
103+
developerConnection POM_SCM_DEV_CONNECTION
104+
}
105+
developers {
106+
developer {
107+
id POM_DEVELOPER_ID
108+
name POM_DEVELOPER_NAME
109+
}
110+
}
111+
}
112+
}
113+
}
114+
115+
// Use default artifact name for the JVM target until we start publishing artifacts for all
116+
// platforms
117+
publications {
118+
jvm {
119+
artifactId = 'okio'
120+
}
121+
}
122+
123+
afterEvaluate {
124+
publications.getByName('kotlinMultiplatform') {
125+
// Source jars are only created for platforms, not the common artifact.
126+
artifact emptySourcesJar
127+
}
128+
}
129+
130+
repositories {
131+
maven {
132+
url isReleaseBuild() ? getReleaseRepositoryUrl() : getSnapshotRepositoryUrl()
133+
credentials {
134+
username getRepositoryUsername()
135+
password getRepositoryPassword()
136+
}
137+
}
138+
maven {
139+
name 'test'
140+
url "file://${rootProject.buildDir}/localMaven"
141+
}
142+
}
143+
}

gradle/wrapper/gradle-wrapper.jar

1.3 KB
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ APP_NAME="Gradle"
2828
APP_BASE_NAME=`basename "$0"`
2929

3030
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
31+
DEFAULT_JVM_OPTS='"-Xmx64m"'
3232

3333
# Use the maximum available, or set MAX_FD != -1 to use that value.
3434
MAX_FD="maximum"

gradlew.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
1414
set APP_HOME=%DIRNAME%
1515

1616
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
17+
set DEFAULT_JVM_OPTS="-Xmx64m"
1818

1919
@rem Find java.exe
2020
if defined JAVA_HOME goto findJavaFromJavaHome

okio/build.gradle

+83-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,85 @@
1-
apply plugin: 'org.jetbrains.kotlin.platform.common'
1+
apply plugin: 'org.jetbrains.kotlin.multiplatform'
22

3-
dependencies {
4-
implementation deps.kotlin.stdLib.common
5-
testImplementation deps.kotlin.test.common
6-
testImplementation deps.kotlin.test.annotations
3+
kotlin {
4+
targets {
5+
// egor: jvmWithJava is getting deprecated but it's not clear what the replacement is. For now
6+
// gonna keep it inside targets {}
7+
fromPreset(presets.jvmWithJava, 'jvm') {
8+
project.sourceSets.test.java.srcDir('jvm/src/test/java')
9+
}
10+
}
11+
js() {
12+
configure([compilations.main, compilations.test]) {
13+
tasks.getByName(compileKotlinTaskName).kotlinOptions {
14+
moduleKind = "commonjs"
15+
}
16+
}
17+
}
18+
iosX64() {
19+
compilations.main.outputKinds 'framework'
20+
}
21+
iosArm64() {
22+
compilations.main.outputKinds 'framework'
23+
}
24+
// Required to generate tests tasks: https://youtrack.jetbrains.com/issue/KT-26547
25+
linuxX64()
26+
macosX64()
27+
mingwX64('winX64')
28+
sourceSets {
29+
commonMain {
30+
kotlin.srcDir('src/main/kotlin')
31+
dependencies {
32+
implementation deps.kotlin.stdLib.common
33+
}
34+
}
35+
commonTest {
36+
kotlin.srcDir('src/test/kotlin')
37+
dependencies {
38+
implementation deps.kotlin.test.common
39+
implementation deps.kotlin.test.annotations
40+
}
41+
}
42+
jvmMain {
43+
kotlin.srcDir('jvm/src/main/java')
44+
resources.srcDir('jvm/src/main/resources')
45+
dependencies {
46+
implementation deps.kotlin.stdLib.jdk6
47+
compileOnly deps.animalSniffer.annotations
48+
}
49+
}
50+
jvmTest {
51+
kotlin.srcDir('jvm/src/test/java')
52+
dependencies {
53+
implementation deps.test.junit
54+
implementation deps.test.assertj
55+
implementation deps.kotlin.test.jdk
56+
}
57+
}
58+
jsMain {
59+
kotlin.srcDir('js/src/main/kotlin')
60+
dependencies {
61+
implementation deps.kotlin.stdLib.js
62+
}
63+
}
64+
jsTest {
65+
kotlin.srcDir('js/src/test/kotlin')
66+
dependencies {
67+
implementation deps.kotlin.test.js
68+
}
69+
}
70+
nativeMain {
71+
kotlin.srcDir('native/src/main/kotlin')
72+
}
73+
nativeTest {
74+
kotlin.srcDir('native/src/test/kotlin')
75+
}
76+
}
77+
configure([targets.iosX64, targets.iosArm64, targets.linuxX64, targets.macosX64, targets.winX64]) {
78+
compilations.main.source(sourceSets.nativeMain)
79+
compilations.test.source(sourceSets.nativeTest)
80+
}
781
}
82+
83+
apply from: 'js/build.gradle'
84+
apply from: 'jvm/jvm.gradle'
85+
apply from: "$rootDir/gradle/gradle-mvn-mpp-push.gradle"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
POM_ARTIFACT_ID=okio
22
POM_NAME=Okio
3-
POM_PACKAGING=jar

okio/js/build.gradle

+29-26
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
apply plugin: 'org.jetbrains.kotlin.platform.js'
1817
apply plugin: 'com.moowork.node'
1918

20-
dependencies {
21-
expectedBy project(':okio')
22-
23-
implementation deps.kotlin.stdLib.js
24-
testImplementation deps.kotlin.test.js
25-
}
26-
27-
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
28-
from compileKotlin2Js.destinationDir
29-
configurations.testCompileClasspath.each {
30-
from zipTree(it.absolutePath).matching { include '*.js' }
31-
}
32-
33-
into "${buildDir}/node_modules"
34-
}
35-
36-
[compileKotlin2Js, compileTestKotlin2Js]*.configure {
37-
kotlinOptions.moduleKind = "commonjs"
38-
}
39-
4019
node {
4120
download = true
4221
}
@@ -45,9 +24,33 @@ task installMocha(type: NpmTask) {
4524
args = ['install', 'mocha']
4625
}
4726

48-
task runMocha(type: NodeTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, installMocha]) {
49-
script = file('node_modules/mocha/bin/mocha')
50-
args = [compileTestKotlin2Js.outputFile]
51-
}
27+
kotlin.targets.matching { it.platformType.name == 'js' }.all { target ->
28+
def testCompilation = target.compilations["test"]
29+
def mainCompilation = target.compilations["main"]
30+
def targetName = target.name
31+
32+
def testCompilationTask = tasks[testCompilation.compileKotlinTaskName]
33+
def mainCompilationTask = tasks[mainCompilation.compileKotlinTaskName]
34+
35+
def populateNodeModules = task populateNodeModules(type: Copy, dependsOn: mainCompilationTask) {
36+
from mainCompilationTask.destinationDir
37+
into "$node.nodeModulesDir/node_modules"
38+
39+
def configuration = testCompilation.runtimeDependencyFiles
40+
from(files {
41+
configuration.collect { File file ->
42+
file.name.endsWith(".jar") ?
43+
zipTree(file.absolutePath).matching {
44+
include '*.js'
45+
} :
46+
files()
47+
}
48+
}.builtBy(configuration))
49+
}
5250

53-
test.dependsOn runMocha
51+
task runMocha(type: NodeTask, dependsOn: [testCompilationTask, populateNodeModules, installMocha]) {
52+
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
53+
args = [testCompilationTask.outputFile]
54+
}
55+
tasks["${targetName}Test"].dependsOn runMocha
56+
}

0 commit comments

Comments
 (0)