Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR build kotlin #725

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fccfe24
added compileKotlin and compileTestKotlin tasks to gradle targeting K…
jack-bolles Aug 2, 2023
0efd26d
THESE TWO FILES ARE TO TEST THE BUILD SCRIPTS. They are not part of t…
jack-bolles Aug 2, 2023
6d860e2
Updated Maven's pom.xml to build the kotlin. Upgraded the pom to use …
jack-bolles Aug 2, 2023
bb341d1
pushing to test build.gradle config with circleCI's androidLint setup…
jack-bolles Aug 2, 2023
bfbd2d1
upgrade gradle to 8.2; fix deprecated syntax to be current version.
jack-bolles Aug 7, 2023
e7e4920
re-set `build.gradle` to before kotlin-for-jvm, isolating upgrade of …
jack-bolles Aug 7, 2023
d0084e4
upgrade version of `com.android.tools.build:gradle` from 7.2.1 to 8.1…
jack-bolles Aug 7, 2023
a5127df
upgrading CircleCI docker android and jdk images to use Java17, as ne…
jack-bolles Aug 7, 2023
16970d8
tweaking CircleCI docker jdk image to use Java17;
jack-bolles Aug 7, 2023
e25ed00
tweaking CircleCI docker jdk image to use Java17;
jack-bolles Aug 7, 2023
3ac3968
tweaking CircleCI docker jdk image to use Java17;
jack-bolles Aug 7, 2023
eb71ddd
[TEMP-NOT FOR PROD] remove "android" build; temporarily create a task…
jack-bolles Aug 9, 2023
5cc4ad7
Debug info for test only failing on circleCI
jack-bolles Aug 9, 2023
b8c2b40
Target `com.android.lint` for Android compatibility checking without …
jack-bolles Aug 9, 2023
9aaccbd
updated jmh plugin; added jvm toolchain resolver in `settings.gradle`
jack-bolles Aug 9, 2023
ffbf6dd
remove `lintDebug` task from circleCI yaml file. Superseded by lint t…
jack-bolles Aug 9, 2023
db57299
consistent formatting and use of quotation marks
jack-bolles Aug 9, 2023
68e50d3
update the `jar` task to fix name of artefact to `javarosa-4.3.0-SNAP…
jack-bolles Aug 9, 2023
af68af0
Intentionally failing build to show that Lint checks do fail the buil…
jack-bolles Aug 9, 2023
7064f6b
Reverting intentional failure demonstration
jack-bolles Aug 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 1 addition & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
version: 2

references:
accept_licenses : &accept_licenses
run:
name: Accept licenses
command: yes | sdkmanager --licenses || true
workspace: &workspace
~/work

android_config: &android_config
working_directory: *workspace
docker:
- image: cimg/android:2022.09.1

jobs:
build:
working_directory: ~/work
docker:
- image: circleci/openjdk:8-jdk
- image: cimg/openjdk:17.0
steps:
- checkout
- restore_cache:
Expand All @@ -39,17 +26,6 @@ jobs:
destination: libs
- store_test_results:
path: build/test-results
check-android-api-level:
<<: *android_config
steps:
- checkout
- *accept_licenses
- run:
name: Android Lint
command: ./gradlew -Pandroid lintDebug --max-workers=1
- store_artifacts:
path: build/reports/lint-results-debug.html
destination: lint-results.html
package:
working_directory: ~/work
docker:
Expand All @@ -76,5 +52,4 @@ workflows:
build_and_package:
jobs:
- build
- check-android-api-level
- package
165 changes: 80 additions & 85 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
buildscript {
ext{
kotlinVersion = "1.8.22"
}
repositories {
google()
mavenCentral()
Expand All @@ -8,24 +11,22 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "me.champeau.jmh:jmh-gradle-plugin:0.6.7"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22"
classpath 'com.android.tools.build:gradle:8.1.0'
classpath "me.champeau.jmh:jmh-gradle-plugin:0.7.1"
}
}

/**
* If `android` is true, the project will be configured as an Android rather than a Java library. This isn't used
* for building archives (such as an APK), but is useful for performing Android checks like lint.
*/
if (!project.hasProperty("android")) {
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'me.champeau.jmh'
} else {
apply plugin: 'com.android.library'
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm' version '1.8.22'
id 'me.champeau.jmh' version '0.7.1'
id 'jacoco'
id 'checkstyle'
}

apply plugin: 'com.android.lint'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this not just be in the plugins block above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work if I do. Gradle complains with org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.lint'] was not found in any of the following sources:


repositories {
google()
mavenCentral()
Expand All @@ -37,19 +38,40 @@ sourceSets {
test.java.srcDirs = ['src/test/java']
test.resources.srcDirs = ['src/test/resources']
}
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

sourceCompatibility = 1.8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to confirm this for myself, but I think (and a bunch of the other Java 8 configs in this file) this can be JavaVersion.VERSION_17 now. Android has made this extra confusing as of late.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defer to your Android knowledge. I erred on the side of caution. LMK what to set it to.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about increasing both the sourceCompatibility and the toolchain language version? That would allow for newer features of the language to be used in the code (sourceCompatibility without toolchain would mean use a newer jdk to build but abstain from using newer syntax in the library code)
However, I am guessing the target compatibility will remain as 1.8 right? As long as the binaries are 1.8 compatible then the same set of android devices should be able to use it without issues.

At least that's how I understand it all. I am not familiar with how ODK javarosa works TBH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about increasing both the sourceCompatibility and the toolchain language version?

Yes. The main client for JavaRosa (https://github.com/getodk/collect) already uses Java 17, so I think we're ok to make the bump. I think you're pointing out here that that would mean incompatibility with other projects that are using an older Java toolchain though - that's something we'd need to update in the README.md.

However, I am guessing the target compatibility will remain as 1.8 right? As long as the binaries are 1.8 compatible then the same set of android devices should be able to use it without issues.

I'm pretty sure that targetCompatibility needs to be the same or newer than sourceCompatibility (https://developer.android.com/build/jdks#target-compat).

targetCompatibility = 1.8

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

compileJava {
options.compilerArgs << "-Xlint:deprecation"
options.encoding = 'UTF-8'
}

compileTestJava {
options.compilerArgs << "-Xlint:deprecation"
options.encoding = 'UTF-8'
}

compileKotlin {
kotlinOptions.jvmTarget = '1.8'
}

compileTestKotlin {
kotlinOptions.jvmTarget = '1.8'
}

targetCompatibility = '1.8'
sourceCompatibility = '1.8'
lint {
htmlReport = true
abortOnError = true
warningsAsErrors = false
checkDependencies = true
}

tasks.register('installLocal') {
def lines = []
Expand Down Expand Up @@ -77,96 +99,69 @@ tasks.register('installLocal') {
}
}

if (!project.hasProperty("android")) {
jar {
baseName = 'javarosa'
// Be sure to update version in pom.xml to match
// snapshot release = x.x.x-SNAPSHOT
// production release = x.x.x
version = '4.3.0-SNAPSHOT'
archiveName = baseName + '-' + version + '.jar'
jar {
archiveBaseName = 'javarosa'
// Be sure to update version in pom.xml to match
// snapshot release = x.x.x-SNAPSHOT
// production release = x.x.x
archiveVersion = '4.3.0-SNAPSHOT'

manifest {
attributes 'Manifest-Version': "$jar.version"
}
manifest {
attributes 'Manifest-Version': archiveVersion
}
}

// TODO: does not build UML diagrams
javadoc {
failOnError = false
}
// TODO: does not build UML diagrams
javadoc {
failOnError = false
}

jacocoTestReport {
reports {
xml.enabled true
}
jacocoTestReport {
reports {
xml.required = true
}
}

// Required to use fileExtensions property in checkstyle file
checkstyle {
toolVersion = '7.6.1'
}
checkstyle {
toolVersion = '7.6.1'
}

jmhJar.doFirst {
new File("build/resources/test").mkdirs()
}
jmhJar.doFirst {
new File("build/resources/test").mkdirs()
}

jmh {
excludes = ["(BenchmarkTemplate)"]
threads = 1
fork = 1
warmup = '2s'
warmupIterations = 10
warmupBatchSize = 1
warmupForks = 1
iterations = 20
timeOnIteration = '2s'
timeUnit = 's'
benchmarkMode = ['avgt', 'ss']
includeTests = true
resultFormat = 'CSV'
forceGC = true

duplicateClassesStrategy = DuplicatesStrategy.WARN
}
} else {
android {
namespace 'com.example'

compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
}
}
}
jmh {
excludes = ["(BenchmarkTemplate)"]
threads = 1
fork = 1
warmup = '2s'
warmupIterations = 10
warmupBatchSize = 1
warmupForks = 1
iterations = 20
timeOnIteration = '2s'
timeUnit = 's'
benchmarkMode = ['avgt', 'ss']
includeTests = true
resultFormat = 'CSV'
forceGC = true

duplicateClassesStrategy = DuplicatesStrategy.WARN
}

dependencies {
// Be sure to update dependencies in pom.xml to match
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22'
implementation 'joda-time:joda-time:2.10.13'
implementation 'org.slf4j:slf4j-api:1.7.33'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1'

// Upgrade to version higher than 1.4 when Collect minSDK >= 26
implementation 'org.apache.commons:commons-csv:1.4'

// Upgrade to version higher than 2.5 when Collect minSDK >= 26
implementation 'commons-io:commons-io:2.5'

implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'

compileOnly 'net.sf.kxml:kxml2:2.3.0'

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
55 changes: 51 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.8.22</kotlin.version>
</properties>
<dependencies>
<!-- Be sure to update dependencies in build.gradle to match -->
Expand Down Expand Up @@ -74,7 +76,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.6.10</version>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -106,9 +108,33 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -204,15 +230,36 @@
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.6.10</version>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<!-- our code is all under ./../java/
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>-->
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<!-- our code is all under ./../java/
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>-->
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version "0.6.0"
}
5 changes: 5 additions & 0 deletions src/main/java/org/javarosa/kotlintest/ThisOrThat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.javarosa.kotlintest

enum class ThisOrThat {
THIS(), THAT(), OTHER()
}