Skip to content

Commit

Permalink
Merge pull request #1 from pkware/mb/updateJabelForPkware
Browse files Browse the repository at this point in the history
Update Jabel for PKware usage
  • Loading branch information
mbayerPK authored Jan 12, 2024
2 parents ad06a0b + 144ec23 commit 7a1e919
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 161 deletions.
40 changes: 30 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
name: CI
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

on: [push, pull_request]
name: Build & test

on:
pull_request:
push:
branches: [ master, release/* ]

jobs:
build:
linux:
name: Linux
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 16
- name: Build with Gradle
run: ./gradlew build
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: 16
distribution: 'temurin'

- uses: burrunan/gradle-cache-action@a54b6ce2cbbba932e5d142129dddef103e6ad143 #v1.19
name: Build with Gradle
with:
arguments: build

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Test Results Linux
path: '**/test-results/**/*.xml'
23 changes: 0 additions & 23 deletions .github/workflows/release.yml

This file was deleted.

80 changes: 77 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Jabel: initialized.
Use the following snippet to add Jabel to your Gradle build:
```gradle
dependencies {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'
annotationProcessor 'com.pkware.jabel:jabel-javac-plugin:0.4.2'
}
// Add more tasks if needed, such as compileTestJava
Expand All @@ -129,6 +129,26 @@ configure([tasks.compileJava]) {
}
```

```kotlin
dependencies {
annotationProcessor("com.pkware.jabel:jabel-javac-plugin:0.4.2")
}

// Add more tasks if needed, such as compileTestJava
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_14.toString() // for the IDE support

options.compilerArgs.addAll(arrayOf("--release 8","--enable-preview"))

doFirst {
// Can be omitted on Java 14 and higher
options.compilerArgs.add("-Xplugin:jabel")

options.compilerArgs.remove("--enable-preview")
}
}
```

Compile your project and verify that the result is still a valid Java 8 bytecode (52.0):
```shell script
$ ./gradlew --no-daemon clean :example:test
Expand All @@ -154,8 +174,8 @@ public class com.example.JabelExample
Gradle 7 supports toolchains and makes it extremely easy to configure everything:
```gradle
dependencies {
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'
compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'
annotationProcessor 'com.pkware.jabel:jabel-javac-plugin:0.4.2'
compileOnly 'com.pkware.jabel:jabel-javac-plugin:0.4.2'
}
configure([tasks.compileJava]) {
Expand All @@ -167,6 +187,24 @@ configure([tasks.compileJava]) {
}
}
```

```kotlin
dependencies {
annotationProcessor("com.pkware.jabel.jabel:jabel-javac-plugin:0.4.2")
compileOnly("com.pkware.jabel:jabel-javac-plugin:0.4.2")
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_16.toString() // for the IDE support
options.release.set(8)

javaCompiler.set(
javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(16))
}
)
}
```
(Java 16 does not require the preview flag for any language feature supported by Jabel)

You can also force your tests to run with Java 8:
Expand All @@ -182,6 +220,23 @@ test {
}
```

```kotlin
tasks.withType<JavaCompile>().configureEach {
if (name == "compileTestJava") {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = sourceCompatibility
}
}

tasks.withType<Test> {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
}
)
}
```

## IDE support

### IntelliJ IDEA
Expand All @@ -194,3 +249,22 @@ If you set `--release=8` flag, the compiler will report usages of APIs that were
* Click "Higher than", and select "8 - Lambdas, type annotations etc." from dropdown

![IntelliJ IDEA Language Level Inspection](docs/images/idea-setting-language-level-inspection.png)

## Releasing
1. Make and checkout a release branch on github.
2. Change the version in gradle.properties to a non-SNAPSHOT version.
3. Run `git commit -am "Release X.Y.Z."` (where X.Y.Z is the new version) in the terminal or command
line.
4. Make a PR with your changes.
5. Merge the release PR after approval, tag the commit on the main branch with
`git tag -a X.Y.Z -m "X.Y.Z"`(X.Y.Z is the new version).
6. Run `git push --tags`.
7. Run `./gradlew publish` in the terminal or command line.
8. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
9. Update `gradle.properties` to the next SNAPSHOT version.
10. Run `git commit -am "Prepare next development version."`
11. Make a PR with your changes.
12. Merge the next version PR after approval.

If step 8 or 9 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 8.

22 changes: 0 additions & 22 deletions build.gradle

This file was deleted.

3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subprojects {
group = "com.pkware.jabel"
}
29 changes: 0 additions & 29 deletions example/build.gradle

This file was deleted.

34 changes: 34 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
java
}

tasks.withType<JavaCompile>().configureEach {
if (name == "compileTestJava") {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = sourceCompatibility
} else {
sourceCompatibility = JavaVersion.VERSION_16.toString()
}

options.release.set(8) // JavaVersion.VERSION_1_8

javaCompiler.set(
javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(21))
}
)
}

tasks.withType<Test> {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
}
)
}

dependencies {
annotationProcessor(project(":jabel-javac-plugin"))
compileOnly(project(":jabel-javac-plugin"))
testImplementation("junit:junit:4.13.2")
}
20 changes: 20 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Project-wide Gradle settings.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError

org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8
kotlin.code.style=official

jabelVersion=1.0.1-1-SNAPSHOT

POM_NAME=Jabel
POM_DESCRIPTION=Mirror of Jabel: https://github.com/bsideup/jabel
32 changes: 0 additions & 32 deletions gradle/publishing.gradle

This file was deleted.

38 changes: 0 additions & 38 deletions jabel-javac-plugin/build.gradle

This file was deleted.

Loading

0 comments on commit 7a1e919

Please sign in to comment.