diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..83c66e2f8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,362 @@ +# One-click release of the Java API: GitHub Packages, a GitHub Release, and the MATLAB jar. +# +# How to release +# 1. Actions -> "Release Java API" -> Run workflow (on master). Leave `version` blank for the next +# patch after the last API_v release (0.11.8_beta -> 0.11.9_beta), or type one. +# 2. Review and merge the ShimmerJavaClass.jar PR it opens in Shimmer-MATLAB-ID. +# 3. Run "Release Android API" in ShimmerAndroidAPI, which builds against this version by default. +# +# The version is not kept in the source. The build files read it from -PreleaseVersion, which this +# workflow passes, and say 'local' otherwise; the API_v tags record what was released. +# +# One run does, in order, and creates nothing public until the build and tests have passed: +# build picks the version; fails if API_v is already tagged; tests ShimmerDriver and builds +# ShimmerDriverPC exactly as gradle.yml does. Read-only: it runs on PRs too. +# publish real releases only, and the only job with packages:write. Publishes shimmerdriver, +# shimmerbluetoothmanager and shimmerdriverpc together with one `gradlew publish` +# (DEV-1115: publishing them one at a time by hand left shimmerbluetoothmanager +# 0.11.8_beta unpublished), and keeps the jars it published for the release +# matlab-jar builds ShimmerJavaClass.jar as Java 8 bytecode (`shadowJar -PmatlabJava8`), on a +# separate runner so its Java 8 classes cannot end up in the published jars +# release tags API_v on the commit it built and creates the GitHub Release, with +# notes from the previous API_v release and the jars attached. It is not marked +# "Latest", which stays with the Consensys releases in this repo. +# update-matlab opens a PR in Shimmer-MATLAB-ID replacing libs/ShimmerJavaClass.jar. Needs the +# MATLAB_REPO_TOKEN secret: a fine-grained token for ShimmerResearch/Shimmer-MATLAB-ID +# with Contents and Pull requests read/write. +# +# A failed job can be re-run on its own with "Re-run failed jobs"; the jobs before it are not +# repeated. A failed publish can leave some of the three versions in GitHub Packages: delete those +# versions under the repo's Packages before re-running, or bump the version. +# +# dry_run runs build and matlab-jar without publishing, from any branch; a blank version still picks +# the next one, so the run shows what a real release would be called. The workflow also +# dry-runs on any PR that changes this file. + +name: Release Java API + +on: + workflow_dispatch: + inputs: + version: + description: 'Version, e.g. 0.12.0_beta. Blank = next patch after the last release' + type: string + required: false + dry_run: + description: 'Build and test only; publish nothing' + type: boolean + default: false + pull_request: + paths: + - '.github/workflows/release.yml' + +concurrency: + group: release-java-api + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours + # Read-only on purpose: this job also runs on PRs, and any code in a job can recover that + # job's token. Only the publish job, which runs on real releases alone, can write packages. + permissions: + contents: read + env: + DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs.dry_run }} + outputs: + version: ${{ steps.version.outputs.version }} + tag: ${{ steps.version.outputs.tag }} + previous_tag: ${{ steps.version.outputs.previous_tag }} + steps: + - name: Release from master only + if: env.DRY_RUN != 'true' && github.ref != 'refs/heads/master' + run: | + echo "::error::A release must run on master, not ${GITHUB_REF_NAME}. Tick dry_run to try another branch." + exit 1 + + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + fetch-depth: 0 # tags, to refuse a version that is already released + # Keep the token out of .git/config, where the Gradle build (and any plugin or dependency + # it runs) could read it. Nothing here needs git credentials after checkout; gh uses GH_TOKEN. + persist-credentials: false + + - name: Choose the version + id: version + env: + GH_TOKEN: ${{ github.token }} + REQUESTED: ${{ inputs.version }} + run: | + PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \ + --jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // ""') + if [ -n "$REQUESTED" ]; then + VERSION=$REQUESTED + else + # Next patch after the last release, keeping its suffix: 0.11.8_beta -> 0.11.9_beta. + last=${PREVIOUS_TAG#API_v} + if ! [[ "$last" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$ ]]; then + echo "::error::Cannot work out the next version from '${PREVIOUS_TAG:-no previous release}'. Type one in the version box." + exit 1 + fi + VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))${BASH_REMATCH[4]}" + fi + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9_.-]*$ ]]; then + echo "::error::'$VERSION' is not a version like 0.11.9_beta." + exit 1 + fi + TAG="API_v$VERSION" + if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then + if [ "$DRY_RUN" = true ]; then + echo "::warning::$TAG already exists, so a real release would stop here. Dry run continues." + else + echo "::error::$TAG already exists. Leave the version blank for the next one, or type another." + exit 1 + fi + fi + { + echo "version=$VERSION" + echo "tag=$TAG" + echo "previous_tag=$PREVIOUS_TAG" + } >> "$GITHUB_OUTPUT" + echo "Releasing $VERSION as $TAG (notes since ${PREVIOUS_TAG:-the first commit})" + + - name: Set up JDK 11 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 + with: + java-version: '11' + distribution: 'temurin' + + # Same pinned action as gradle.yml, and likewise no gradle-version: build through the + # committed wrapper. + - name: Setup Gradle + uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 + + - name: Test ShimmerDriver + working-directory: ShimmerDriver + run: ./gradlew test + + # ShimmerDriverPC includes :ShimmerDriver and :ShimmerBluetoothManager as subprojects. + - name: Build ShimmerDriverPC + working-directory: ShimmerDriverPC + run: ./gradlew build + + publish: + needs: build + if: github.event_name == 'workflow_dispatch' && !inputs.dry_run + runs-on: ubuntu-latest + timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours + permissions: + contents: read + packages: write + env: + VERSION: ${{ needs.build.outputs.version }} + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # publish gets its token explicitly, below + + - name: Set up JDK 11 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 + with: + java-version: '11' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 + + # `publish` runs in every project of the ShimmerDriverPC build, so all three artifacts go + # out in one invocation, and -PreleaseVersion versions all three (and their POM + # dependencies on each other). It builds the jars but does not re-run the tests, which the + # build job ran on this same commit. The build files read the credentials from USERNAME and TOKEN. + - name: Publish to GitHub Packages + working-directory: ShimmerDriverPC + env: + USERNAME: ${{ github.actor }} + TOKEN: ${{ github.token }} + run: ./gradlew publish -PreleaseVersion="$VERSION" + + # The jars just published, so the GitHub Release carries the same files as GitHub Packages. + - name: Collect the published jars + run: | + mkdir -p release-assets + cp ShimmerDriver/build/libs/ShimmerDriver.jar "release-assets/shimmerdriver-$VERSION.jar" + cp ShimmerBluetoothManager/build/libs/ShimmerBluetoothManager.jar "release-assets/shimmerbluetoothmanager-$VERSION.jar" + cp ShimmerDriverPC/build/libs/ShimmerDriverPC.jar "release-assets/shimmerdriverpc-$VERSION.jar" + ls -l release-assets + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: release-jars + path: release-assets/ + if-no-files-found: error + + matlab-jar: + needs: build + runs-on: ubuntu-latest + timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours + permissions: + contents: read + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # the Gradle build needs no git credentials + + - name: Set up JDK 11 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 + with: + java-version: '11' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 + + - name: Build ShimmerJavaClass.jar for MATLAB (Java 8 bytecode) + working-directory: ShimmerDriverPC + run: ./gradlew shadowJar -PmatlabJava8 + + # Every class in the jar, dependencies included, since a dependency built for a later Java + # breaks MATLAB just as surely as our own code would (~32,500 classes, about 2 s). + - name: Check every class in the jar is Java 8 bytecode + run: | + jar=ShimmerDriverPC/build/libs/ShimmerJavaClass.jar + python3 - "$jar" <<'EOF' + import struct, sys, zipfile + + MAIN = "com/shimmerresearch/tools/matlab/ShimmerJavaClass.class" + jar = sys.argv[1] + checked, bad = 0, [] + with zipfile.ZipFile(jar) as z: + names = z.namelist() + if MAIN not in names: + print(f"::error::{jar} does not contain {MAIN}.") + sys.exit(1) + for name in names: + # Java 8 never loads module descriptors or multi-release entries for later Javas. + if (not name.endswith(".class") or name.startswith("META-INF/versions/") + or name.endswith("module-info.class")): + continue + with z.open(name) as f: + head = f.read(8) + checked += 1 + if len(head) < 8 or head[:4] != b"\xca\xfe\xba\xbe": + bad.append((name, "not a class file")) + elif struct.unpack(">H", head[6:8])[0] > 52: + bad.append((name, f"class version {struct.unpack('>H', head[6:8])[0]}")) + print(f"Checked {checked} classes; {len(bad)} newer than Java 8 (class version 52).") + for name, why in bad[:20]: + print(f"::error::{name}: {why}. MATLAB on Java 8 cannot load it.") + if len(bad) > 20: + print(f"::error::...and {len(bad) - 20} more.") + sys.exit(1 if bad else 0) + EOF + mkdir -p matlab-jar + cp "$jar" matlab-jar/ShimmerJavaClass.jar + ls -l matlab-jar + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: matlab-jar + path: matlab-jar/ + if-no-files-found: error + + release: + needs: [build, publish, matlab-jar] + if: github.event_name == 'workflow_dispatch' && !inputs.dry_run + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write # create the tag and the release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.build.outputs.version }} + TAG: ${{ needs.build.outputs.tag }} + PREVIOUS_TAG: ${{ needs.build.outputs.previous_tag }} + steps: + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: release-jars + path: release-assets + + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: matlab-jar + path: matlab-jar + + - name: Create the tag and GitHub Release + run: | + cp matlab-jar/ShimmerJavaClass.jar "release-assets/ShimmerJavaClass-$VERSION.jar" + gh release create "$TAG" release-assets/* \ + --repo "$GITHUB_REPOSITORY" \ + --target "$GITHUB_SHA" \ + --title "Shimmer Java API Rev $VERSION" \ + --generate-notes ${PREVIOUS_TAG:+--notes-start-tag "$PREVIOUS_TAG"} \ + --latest=false + { + echo "### Released Java API $VERSION" + echo "- Release: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG" + echo "- Packages: com.shimmerresearch:shimmerdriver, shimmerbluetoothmanager and shimmerdriverpc at $VERSION" + echo "- Next: merge the MATLAB PR, then run Release Android API in ShimmerAndroidAPI; it builds against $VERSION unless you pick another driver version." + } >> "$GITHUB_STEP_SUMMARY" + + update-matlab: + needs: [build, release] + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: {} # writes to Shimmer-MATLAB-ID with MATLAB_REPO_TOKEN, not this repo's token + env: + VERSION: ${{ needs.build.outputs.version }} + TAG: ${{ needs.build.outputs.tag }} + MATLAB_REPO: ShimmerResearch/Shimmer-MATLAB-ID + BRANCH: ShimmerJavaClass_${{ needs.build.outputs.version }} + HAS_TOKEN: ${{ secrets.MATLAB_REPO_TOKEN != '' }} + steps: + - name: Check for MATLAB_REPO_TOKEN + if: env.HAS_TOKEN != 'true' + run: | + echo "::error::Secret MATLAB_REPO_TOKEN is not set, so the Shimmer-MATLAB-ID PR cannot be opened. Add a fine-grained token for $MATLAB_REPO (Contents and Pull requests: read/write) as a repo secret, then re-run this job." + exit 1 + + # Credentials stay persisted here on purpose: the git push below uses them. Nothing else runs + # in this job. + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + repository: ${{ env.MATLAB_REPO }} + token: ${{ secrets.MATLAB_REPO_TOKEN }} + path: matlab + + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: matlab-jar + path: matlab-jar + + - name: Open the PR updating libs/ShimmerJavaClass.jar + env: + GH_TOKEN: ${{ secrets.MATLAB_REPO_TOKEN }} + working-directory: matlab + run: | + existing=$(gh pr list --repo "$MATLAB_REPO" --head "$BRANCH" --state open --json url --jq '.[0].url // ""') + if [ -n "$existing" ]; then + echo "PR already open: $existing" + echo "- MATLAB PR: $existing" >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + cp ../matlab-jar/ShimmerJavaClass.jar libs/ShimmerJavaClass.jar + if git diff --quiet -- libs/ShimmerJavaClass.jar; then + echo "libs/ShimmerJavaClass.jar is already this build; no PR needed." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "$BRANCH" + git add libs/ShimmerJavaClass.jar + git commit -m "Update ShimmerJavaClass.jar to Shimmer Java API $VERSION" \ + -m "Built by $GITHUB_REPOSITORY's Release workflow from $TAG ($GITHUB_SHA), as Java 8 bytecode." + git push --force origin "HEAD:refs/heads/$BRANCH" + url=$(gh pr create --repo "$MATLAB_REPO" --base master --head "$BRANCH" \ + --title "Update ShimmerJavaClass.jar to Shimmer Java API $VERSION" \ + --body "Replaces \`libs/ShimmerJavaClass.jar\` with the build from [$TAG]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG) (\`$GITHUB_SHA\`), compiled as Java 8 bytecode with \`gradlew shadowJar -PmatlabJava8\`. + + Opened by the [Release Java API run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID).") + echo "Opened $url" + echo "- MATLAB PR: $url" >> "$GITHUB_STEP_SUMMARY" diff --git a/AGENTS.md b/AGENTS.md index 5e47628f6..987a978b2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,6 +18,27 @@ all: they are legacy Eclipse ADT Android projects. Test results land in `**/build/test-results/test/*.xml`. +## Releasing +Releases are cut by the **Release Java API** workflow (`release.yml`), not from a developer machine, +and need no uprev PR: +1. Run the workflow on `master`. Leave `version` blank for the next patch after the last `API_v` + release, or type one. It tests and builds as CI does, publishes all three artifacts to GitHub + Packages in one `gradlew publish`, tags `API_v`, and creates the GitHub Release with the + jars attached (not marked Latest — that stays with Consensys). +2. It also builds `ShimmerJavaClass.jar` for MATLAB and opens a PR replacing + `Shimmer-MATLAB-ID/libs/ShimmerJavaClass.jar` (needs the `MATLAB_REPO_TOKEN` secret). Review and + merge it. +3. Run `ShimmerAndroidAPI`'s own Release workflow, which builds against the newest Java release unless + told otherwise. + +The version is not stored in the source: the three publishing blocks read `-PreleaseVersion`, which +the workflow passes, and fall back to `local`. The `API_v` tags are the record of what was released. + +`ShimmerJavaClass.jar` must be Java 8 bytecode, because MATLAB may load it on Java 8. Build it locally +with `cd ShimmerDriverPC && ./gradlew shadowJar -PmatlabJava8`, which compiles all three projects with +`--release 8` — that also rejects any API newer than Java 8, so `Process.onExit()`, `var` and the like +fail the build here instead of throwing `NoSuchMethodError` inside MATLAB. + ## Subprojects | Project | Role | |---|---| diff --git a/ShimmerBluetoothManager/build.gradle b/ShimmerBluetoothManager/build.gradle index b5ed8183e..6bf3cb637 100644 --- a/ShimmerBluetoothManager/build.gradle +++ b/ShimmerBluetoothManager/build.gradle @@ -27,7 +27,7 @@ publishing { groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerbluetoothmanager' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( @@ -40,7 +40,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your @@ -68,3 +68,14 @@ dependencies { // 'test.useTestNG()' to your build script. testImplementation 'junit:junit:4.12' } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} diff --git a/ShimmerDriver/build.gradle b/ShimmerDriver/build.gradle index 8cce51299..8d62a7215 100644 --- a/ShimmerDriver/build.gradle +++ b/ShimmerDriver/build.gradle @@ -49,7 +49,7 @@ publishing { groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerdriver' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( @@ -63,7 +63,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your @@ -173,3 +173,14 @@ tasks.withType(Test).configureEach { } } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java b/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java index 254d1ce60..360d54199 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java @@ -153,11 +153,20 @@ public int startServer() throws Exception { e.printStackTrace(); } }); - runningProcess.onExit().thenAccept(p -> { - int code = p.exitValue(); - System.err.println("[BLEGrpcServer] exited: code=" + code + - (code >= 128 ? " (likely signal " + (code - 128) + ")" : "")); - }); + // Not Process.onExit(): that is Java 9+, and MATLAB loads this class on Java 8 via + // ShimmerJavaClass.jar, where it throws NoSuchMethodError. Daemon, like onExit()'s pool thread. + final Process process = runningProcess; + Thread exitWatcher = new Thread(() -> { + try { + int code = process.waitFor(); + System.err.println("[BLEGrpcServer] exited: code=" + code + + (code >= 128 ? " (likely signal " + (code - 128) + ")" : "")); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }, "BLEGrpcServer-exit"); + exitWatcher.setDaemon(true); + exitWatcher.start(); processThread.start(); return port; diff --git a/ShimmerDriverPC/build.gradle b/ShimmerDriverPC/build.gradle index 00ee312ac..623db5df3 100644 --- a/ShimmerDriverPC/build.gradle +++ b/ShimmerDriverPC/build.gradle @@ -41,10 +41,15 @@ publishing { publications { mavenJava(MavenPublication) { from components.java + // The Shadow plugin adds ShimmerJavaClass.jar (no classifier) to components.java, where it + // collides with the plain jar and fails publish on Gradle 8. Publish the plain jar with its + // dependencies in the POM, as releases up to 0.11.7_beta did; the fat jar goes to MATLAB + // and the GitHub Release instead. + components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) { skip() } groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerdriverpc' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( @@ -57,7 +62,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your @@ -110,12 +115,18 @@ dependencies { implementation("org.bouncycastle:bcprov-jdk15on:1.61") } -// Shadow JAR task to create a runnable JAR with dependencies -/* -Change to using the following below for ShimmerDriverPC/ShimmerDriver/ShimmerBluetoothManager -sourceCompatibility = '1.8' // Ensure code is compiled with Java 8 -targetCompatibility = '1.8' // Ensure bytecode is compatible with Java 8 -*/ +// Shadow JAR task to create a runnable JAR with dependencies. +// ShimmerJavaClass.jar is loaded by MATLAB, which may run it on Java 8, so build it as Java 8 +// bytecode with: ./gradlew shadowJar -PmatlabJava8 +// This applies to the ShimmerDriver and ShimmerBluetoothManager subprojects too, so their build files +// no longer need editing to 1.8 by hand. --release 8 also fails the compile if the code uses an API +// newer than Java 8, which sourceCompatibility = '1.8' alone would let through to fail in MATLAB. +// The "Release Java API" workflow builds the jar this way and opens a PR into Shimmer-MATLAB-ID/libs. +if (hasProperty('matlabJava8')) { + allprojects { + tasks.withType(JavaCompile).configureEach { options.release = 8 } + } +} shadowJar { archiveBaseName.set('ShimmerJavaClass') // Use archiveBaseName instead of baseName archiveClassifier.set('') // Remove classifier so it’s named shimmerjavaclass.jar @@ -126,3 +137,14 @@ shadowJar { mergeServiceFiles() // Merges service files (if any) } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} diff --git a/ShimmerLSL/build.gradle b/ShimmerLSL/build.gradle index 4227dc2c0..419de8816 100644 --- a/ShimmerLSL/build.gradle +++ b/ShimmerLSL/build.gradle @@ -39,7 +39,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your diff --git a/ShimmerPCBasicExamples/build.gradle b/ShimmerPCBasicExamples/build.gradle index e3b8eb351..213a64eab 100644 --- a/ShimmerPCBasicExamples/build.gradle +++ b/ShimmerPCBasicExamples/build.gradle @@ -22,7 +22,7 @@ repositories { } maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your