Skip to content

Commit

Permalink
secp-api/secp-bouncy: backport to Java 8
Browse files Browse the repository at this point in the history
* IDEs will see secp-api, secp-bouncy modules as Java 9
* apiModuleJavaCompatibility property is used with `org.beryx.jar` Gradle
  plugin to create Java 8 JARs with module-info on official builds
* Remove usages of Java 9 API in secp-api and secp-bouncy

Developers of secp-jdk using IDEs will need to be aware that the
actual requirements are Java 8 API. But mistakes will be caught by
CI.
  • Loading branch information
msgilligan committed Feb 27, 2025
1 parent 4b49c82 commit de600d7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
- name: Install secp256k1 with Nix
run: nix profile install nixpkgs#secp256k1
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew -PapiModuleJavaCompatibility=8 build
- name: Run Java & Kotlin Examples
run: ./gradlew run runEcdsa
run: ./gradlew -PapiModuleJavaCompatibility=8 run runEcdsa


build_nix:
Expand All @@ -59,4 +59,4 @@ jobs:
- name: Install secp256k1 with Nix
run: nix profile install nixpkgs#secp256k1
- name: Build in Nix development shell
run: nix develop -c gradle build run runEcdsa
run: nix develop -c gradle -PapiModuleJavaCompatibility=8 build run runEcdsa
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nixos-devshell:
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
- nix profile install nixpkgs#secp256k1
script:
- nix develop .#minimum -c gradle build run runEcdsa
- nix develop .#minimum -c gradle -PapiModuleJavaCompatibility=8 build run runEcdsa
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
Expand All @@ -26,4 +26,4 @@ trixie-gradlew:
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
- nix profile install nixpkgs#secp256k1
script:
- ./gradlew build run runEcdsa
- ./gradlew -PapiModuleJavaCompatibility=8 build run runEcdsa
10 changes: 9 additions & 1 deletion secp-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
plugins {
id 'java-library'
id 'org.beryx.jar' version '2.0.0'
}

tasks.withType(JavaCompile).configureEach {
options.release = 9
// IDEs and other tools will see `9` by default, but CI and release builds
// will set `-PapiModuleJavaCompatibility=8` to generate a Java 8 JAR
// and the `org.beryx.jar` plugin will put `module-info.jar` in the Java 8 JAR.
options.release = (findProperty('apiModuleJavaCompatibility') ?: 9) as int
}

ext.moduleName = 'org.bitcoinj.secp.api'

moduleConfig {
version = project.version
}

dependencies {
api("org.jspecify:jspecify:1.0.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;

/**
*
Expand Down Expand Up @@ -65,8 +66,7 @@ static Secp256k1Provider find() {
*/
static Optional<Secp256k1Provider> findFirst(Predicate<Secp256k1Provider> filter) {
ServiceLoader<Secp256k1Provider> loader = ServiceLoader.load(Secp256k1Provider.class);
return loader.stream()
.map(ServiceLoader.Provider::get)
return StreamSupport.stream(loader.spliterator(), false)
.filter(filter)
.findFirst();
}
Expand All @@ -76,7 +76,7 @@ static Optional<Secp256k1Provider> findFirst(Predicate<Secp256k1Provider> filter
* @param provider a candidate provider
* @return true if it should be "found"
*/
private static boolean defaultFilter(Secp256k1Provider provider) {
/* private */ static boolean defaultFilter(Secp256k1Provider provider) {
return provider.name().equals("ffm");
}
}
10 changes: 9 additions & 1 deletion secp-bouncy/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
plugins {
id 'java-library'
id 'org.beryx.jar' version '2.0.0'
}

tasks.withType(JavaCompile).configureEach {
options.release = 9
// IDEs and other tools will see `9` by default, but CI and release builds
// will set `-PapiModuleJavaCompatibility=8` to generate a Java 8 JAR
// and the `org.beryx.jar` plugin will put `module-info.jar` in the Java 8 JAR.
options.release = (findProperty('apiModuleJavaCompatibility') ?: 9) as int
}

ext.moduleName = 'org.bitcoinj.secp.bouncy'

moduleConfig {
version = project.version
}

dependencies {
api project(':secp-api')
api 'org.bouncycastle:bcprov-jdk18on:1.78.1' // TODO: Make this a non-API dependency, see BouncyPrivKey
Expand Down

0 comments on commit de600d7

Please sign in to comment.