如何基于自定义Corda分支构建CordApp并关联自定义编译JAR文件?
Hey there! Since you're new to Gradle and Corda, let's break this down step by step—no confusing jargon, promise. Here's exactly how to swap out the default Corda version with your custom-built JARs for your test CordApp:
Step 1: Organize Your Custom Corda JARs
First, create a libs folder at the root of your CordApp project (the same level as your contracts, workflows, and client modules). Copy all the JARs you compiled from your modified Corda code into this folder—make sure you include all core modules like corda-core.jar, corda-node.jar, corda-common.jar, and any others your CordApp relies on.
Step 2: Update Gradle Repositories to Use Local JARs
For each module in your CordApp (like contracts/build.gradle and workflows/build.gradle), you need to tell Gradle to look for dependencies in your local libs folder. Add this to the repositories block:
repositories { // Add this flatDir entry to pull from your local libs folder flatDir { dirs '../libs' // Path relative to the module's build.gradle file } // Keep other existing repositories (like mavenCentral) for non-Corda dependencies mavenCentral() // ... any other repos you already have }
Step 3: Replace Default Corda Dependencies with Local JARs
Next, modify the dependencies block in each module's build.gradle to remove the default Corda references and point to your custom JARs.
Before (default setup):
dependencies { cordaCompile "$corda_release_group:corda-core:$corda_release_version" cordaCompile "$corda_release_group:corda-node:$corda_release_version" // ... other Corda-related dependencies }
After (using your custom JARs):
You can choose between two approaches, depending on your preference:
Option 1: Explicit single JAR references (more precise)
dependencies { // Replace each default Corda dependency with your custom JAR compile files('../libs/corda-core-3.3-custom.jar') compile files('../libs/corda-node-3.3-custom.jar') compile files('../libs/corda-common-3.3-custom.jar') // ... add other custom Corda modules your app needs // Keep non-Corda dependencies (like JUnit, log4j) as-is testCompile 'junit:junit:4.12' // ... }
Option 2: File tree for all matching Corda JARs (saves typing)
If you named your JARs consistently (e.g., all start with corda-), this will pull all relevant files automatically:
dependencies { compile fileTree(dir: '../libs', include: ['corda-*.jar']) // Keep non-Corda dependencies testCompile 'junit:junit:4.12' // ... }
Step 4: Clean Up Old Configuration
Go to your project's root build.gradle file and comment out or delete these lines—you won't need them anymore since you're using local JARs:
// corda_release_group = 'net.corda' // corda_release_version = '3.3-corda' // corda_gradle_plugins_version = '3.2.1' // Keep this only if you didn't modify the Corda Gradle plugins
Note: If you made changes to Corda's Gradle plugins themselves, you'll need to compile those plugins separately and reference them locally too—but since you're just modifying the hash function, you can probably keep the original plugin version.
Step 5: Test the Build
Run this command from your project root to build your CordApp with the custom Corda version:
./gradlew clean build
If you run into dependency conflicts, double-check that you've replaced all default net.corda dependencies and that your custom JARs include all required classes.
内容的提问来源于stack exchange,提问作者SirAndrew00

