diff --git a/smart-contract/hyperledger-fabric/v2/java/.gitignore b/smart-contract/hyperledger-fabric/v2/java/.gitignore index 9709c31..f8ca0e4 100644 --- a/smart-contract/hyperledger-fabric/v2/java/.gitignore +++ b/smart-contract/hyperledger-fabric/v2/java/.gitignore @@ -9,13 +9,7 @@ build/ !**/src/test/**/build/ ### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr +.idea/ out/ !**/src/main/**/out/ !**/src/test/**/out/ diff --git a/smart-contract/hyperledger-fabric/v2/java/README.md b/smart-contract/hyperledger-fabric/v2/java/README.md index 5a3aed0..3ec87c9 100644 --- a/smart-contract/hyperledger-fabric/v2/java/README.md +++ b/smart-contract/hyperledger-fabric/v2/java/README.md @@ -15,6 +15,16 @@ However, note that normally, you do not need to locally build the chaincode. The [test network](../../../../test-network/README.adoc) will build generate this JAR as part of a [dockerized](https://www.docker.com/) build process. Build directly only if you know what you are doing. +## Development + +You most likely do not want to build with OpenJML for local development, eg in your IDE. +To disable OpenJML, simply set the `withoutOpenJML` Gradle property to `true`. +For example, in `gradle.properties`: + +```properties +withoutOpenJML = "true" +``` + ## License diff --git a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts index d1fa38e..7467de7 100644 --- a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts +++ b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts @@ -12,6 +12,9 @@ val downloadDir = layout.buildDirectory.dir("tmp/download") val jmlavac = openJMLJavaHomeDir.file("bin/jmlavac") val jmlava = openJMLJavaHomeDir.file("bin/jmlava") +val withoutOpenJML: String? by project +val noOpenJML: Boolean = withoutOpenJML != null && withoutOpenJML.toBoolean() + plugins { application id("com.github.johnrengelman.shadow") version "7.1.2" @@ -49,8 +52,6 @@ dependencies { application { mainClass.set("org.hyperledger.fabric.contract.ContractRouter") } tasks.named("shadowJar") { - dependsOn(tasks.named("initOpenJML")) - archiveBaseName.set("chaincode") archiveClassifier.set("") archiveVersion.set("") @@ -58,63 +59,65 @@ tasks.named("shadowJar") { tasks.named("test") { useJUnitPlatform() } -tasks.test { - java { - executable = "$openJMLDir/bin/jmlava" - jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception") +if (!noOpenJML) { + tasks.named("shadowJar") { + dependsOn(tasks.named("initOpenJML")) } -} -// java { -// sourceCompatibility = JavaVersion.VERSION_17 -// targetCompatibility = JavaVersion.VERSION_17 -// } + tasks.test { + java { + executable = "$openJMLDir/bin/jmlava" + jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception") + } + } -tasks.withType().configureEach { - dependsOn(tasks.named("initOpenJML")) - // Only when not compiling because of Spotless - if (!gradle.startParameter.taskNames.any { it.contains("spotlessApply") }) { - val mode = + tasks.withType().configureEach { + dependsOn(tasks.named("initOpenJML")) + // Only when not compiling because of Spotless + if (!gradle.startParameter.taskNames.any { it.contains("spotlessApply") }) { + val mode = when (System.getenv("JML_MODE")) { "esc" -> "esc" else -> "rac" } - options.isFork = true - options.compilerArgs.addAll( + options.isFork = true + options.compilerArgs.addAll( listOf( - "-jml", "-$mode", "-timeout", "30", "--nullable-by-default", "--specs-path", "specs/")) - options.forkOptions.javaHome = openJMLJavaHomeDir.asFile + "-jml", "-$mode", "-timeout", "30", "--nullable-by-default", "--specs-path", "specs/")) + options.forkOptions.javaHome = openJMLJavaHomeDir.asFile + } } -} -configure { - java { - importOrder() - removeUnusedImports() - googleJavaFormat() - formatAnnotations() - toggleOffOn() + configure { + java { + importOrder() + removeUnusedImports() + googleJavaFormat() + formatAnnotations() + toggleOffOn() + } + kotlin { + target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt") + ktfmt() + } + kotlinGradle { ktfmt() } } - kotlin { - target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt") - ktfmt() + + tasks.register("initOpenJML") { + val openJMLVersion: String by project + + val zipFile: File = downloadDir.get().file("openjml.zip").asFile + downloadOpenJML(openJMLVersion, zipFile, logger) + extractOpenJML(zipFile, openJMLDir, logger) + + // `jmlavac' is what we call `javac' that is actually + // OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with + // OpenJML already in the classpath + generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger) + replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger) + generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger) + replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger) + logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir") } - kotlinGradle { ktfmt() } } -tasks.register("initOpenJML") { - val openJMLVersion: String by project - - val zipFile: File = downloadDir.get().file("openjml.zip").asFile - downloadOpenJML(openJMLVersion, zipFile, logger) - extractOpenJML(zipFile, openJMLDir, logger) - - // `jmlavac' is what we call `javac' that is actually - // OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with - // OpenJML already in the classpath - generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger) - replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger) - generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger) - replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger) - logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir") -} diff --git a/smart-contract/hyperledger-fabric/v2/java/gradle.properties b/smart-contract/hyperledger-fabric/v2/java/gradle.properties index 11e657e..7dc39e1 100644 --- a/smart-contract/hyperledger-fabric/v2/java/gradle.properties +++ b/smart-contract/hyperledger-fabric/v2/java/gradle.properties @@ -1 +1,2 @@ openJMLVersion = 0.17.0-alpha-15 +withoutOpenJML = true \ No newline at end of file