Skip to content

Commit

Permalink
- adaptations to generate wallets and bitcoind jars
Browse files Browse the repository at this point in the history
 - require a more careful definition of dependencies considering version
   (full group-artifact-version definition)
  • Loading branch information
rodvar committed Nov 5, 2024
1 parent 60ef746 commit 912c078
Show file tree
Hide file tree
Showing 28 changed files with 174 additions and 99 deletions.
2 changes: 1 addition & 1 deletion account/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies {
implementation(project(":security"))
implementation(project(":identity"))

implementation("network:network")
implementation("network:network:$version")
}
2 changes: 1 addition & 1 deletion application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation(project(":offer"))
implementation(project(":trade"))

implementation("network:network")
implementation("network:network:$version")

implementation(libs.typesafe.config)
}
1 change: 0 additions & 1 deletion apps/desktop/desktop-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import bisq.gradle.common.getPlatform
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

import java.util.Properties
import java.io.File

// Function to read properties from a file - TODO find a way to reuse this code instead of copying when needed
fun readPropertiesFile(filePath: String): Properties {
Expand Down
8 changes: 4 additions & 4 deletions bisq-easy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dependencies {
implementation(project(":support"))
implementation(project(":presentation"))

implementation("network:network")
implementation("network:network-identity")
implementation("bitcoind:core")
implementation("wallets:wallet")
implementation("network:network:$version")
implementation("network:network-identity:$version")
implementation("bitcoind:core:$version")
implementation("wallets:wallet:$version")
// implementation("wallets:electrum")
// implementation("wallets:bitcoind")

Expand Down
4 changes: 2 additions & 2 deletions bonded-roles/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ dependencies {
implementation(project(":identity"))
implementation(project(":settings"))

implementation("network:network-identity")
implementation("network:network")
implementation("network:network-identity:$version")
implementation("network:network:$version")

implementation(libs.google.gson)
implementation(libs.typesafe.config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
}

val bisqVersion = extensions.getByType<VersionCatalogsExtension>().named("libs").findVersion("bisq").getOrNull()
//println("bisq.java-library: BISQ version for platform $bisqVersion")

dependencies {
api(platform("bisq:platform:$bisqVersion"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bisq.gradle.maven_publisher

import groovy.util.Node
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
Expand All @@ -17,15 +18,18 @@ import java.util.*
*/
class LocalMavenPublishPlugin : Plugin<Project> {
companion object {
const val GROUP_SEPARATOR = "."
val COMPOSITE_PROJECTS_TO_INCLUDE = listOf("tor", "socks5-socket-channel")
const val DEFAULT_GROUP = "bisq"
val COMPOSITE_PROJECTS_TO_INCLUDE = listOf("tor", "network", "wallets", "bitcoind")
}

private var rootVersion = "unspecified"

override fun apply(project: Project) {
this.loadRootVersion(project)
applyTaskRecursively(project, getRootGroup(project))
if (rootVersion == "unspecified") {
this.loadRootVersion(project)
}
val group = getRootGroup(project);
applyTaskRecursively(project, group)
}

private fun applyTaskRecursively(project: Project, group: String) {
Expand All @@ -38,7 +42,6 @@ class LocalMavenPublishPlugin : Plugin<Project> {
applyPublishPlugin(project, group)
} else {
project.subprojects {
// applyTaskRecursively(this, "${group}${GROUP_SEPARATOR}${project.name}")
applyTaskRecursively(this, group)
}

Expand All @@ -61,64 +64,33 @@ class LocalMavenPublishPlugin : Plugin<Project> {
project.afterEvaluate {
val javaComponent = project.components.findByName("java")
if (javaComponent != null) {
// Apply a default version to dependencies without a specified version
// project.configurations.all {
// resolutionStrategy.eachDependency {
// if (isVersionUnspecified(requested.version)) {
// useVersion(project.version.toString()) // Apply the project's version as a default
// }
// }
// }
val protoSourcesJar = project.tasks.register("protoSourcesJar", Jar::class.java) {
val protoSourcesJar = project.tasks.findByName("protoSourcesJar") ?: project.tasks.register("protoSourcesJar", Jar::class.java) {
archiveClassifier.set("proto-sources")
from(project.fileTree("${project.layout.buildDirectory}/generated/source/proto/main")) // Adjust path if needed
}

if (rootVersion == "unspecified") {
throw IllegalStateException("Root project version not set. Please set the rootVersion property.")
}
project.extensions.configure<PublishingExtension>("publishing") {
publications {
create("mavenJava", MavenPublication::class) {
// val publicationName = if (group == DEFAULT_GROUP) "mavenJava" else "mavenJava_${group}"
val publicationName = "mavenJava"
create(publicationName, MavenPublication::class) {
from(project.components["java"]) // Adjust if publishing other types (like Kotlin)
artifactId = project.name
groupId = group
version = rootVersion

// versionMapping {
// usage("java-api") {
// fromResolutionOf("runtimeClasspath")
// }
// usage("java-runtime") {
// fromResolutionResult()
// }
// }

// Include the Protobuf sources JAR
artifact(protoSourcesJar)

// hack to make sure the pom generated is compliant (without this it generates dependencies without the version)
pom.withXml {
val rootNode = asNode()

// val addPlatformDependencies = handlePlatformDependency(rootNode)

// Get all nodes with a name ending in "dependencies"
val dependenciesNodes = rootNode.children().filter {
(it as? groovy.util.Node)?.name().toString().endsWith("dependencies")
}.map { it as groovy.util.Node }

// fixes corrupted pom not resolving dependencies when not explicitly specified in gradle configuration
val dependenciesNode = dependenciesNodes.firstOrNull() ?: rootNode.appendNode("dependencies")
dependenciesNode.children().forEach { dependencyNode ->
if (dependencyNode is groovy.util.Node) {
val versionNodes = dependencyNode.children().filter {
(it as? groovy.util.Node)?.name().toString().endsWith("version")
}.map { it as groovy.util.Node }
if (versionNodes.isEmpty()) {
// dependencyNode.appendNode("${rootNode.name().toString().removeSuffix("project")}version", "[${project.version}]")
dependencyNode.appendNode("version", rootVersion)
} else if (versionNodes[0].value().toString() == "unspecified") {
throw Error("${versionNodes[0].toString()} fucked")
}
}
}
setupPublication(project, group, protoSourcesJar)
}
if (group != DEFAULT_GROUP) {
create("mavenJava_bisqAlias", MavenPublication::class) {
groupId = "bisq"
artifactId = project.name
version = rootVersion

setupPublication(project, group, protoSourcesJar, true)
}
}
}
Expand All @@ -135,9 +107,45 @@ class LocalMavenPublishPlugin : Plugin<Project> {
}
}

private fun loadRootVersion(project: Project) {
// Load properties from root gradle.properties file
val rootPropertiesFile = File(getRootGradlePropertiesFile(project), "gradle.properties")
private fun MavenPublication.setupPublication(project: Project, group: String, protoSourcesJar: Any, isAlias: Boolean = false) {
// Include the Protobuf sources JAR
artifact(protoSourcesJar)
// Reference the primary artifact and files
if (isAlias) {
artifact(project.tasks.named("jar"))
}

// hack to make sure the pom generated is compliant (without this it generates dependencies without the version)
pom.withXml {
val rootNode = asNode()
if (isAlias) {
rootNode.appendNode("description", "Alias of $group:${project.name}")
}

// Get all nodes with a name ending in "dependencies"
val dependenciesNodes = rootNode.children().filter {
(it as? Node)?.name().toString().endsWith("dependencies")
}.map { it as Node }

// fixes corrupted pom not resolving dependencies when not explicitly specified in gradle configuration
val dependenciesNode = dependenciesNodes.firstOrNull() ?: rootNode.appendNode("dependencies")
dependenciesNode.children().forEach { dependencyNode ->
if (dependencyNode is Node) {
val versionNodes = dependencyNode.children().filter {
(it as? Node)?.name().toString().endsWith("version")
}.map { it as Node }
if (versionNodes.isEmpty()) {
dependencyNode.appendNode("version", rootVersion)
}
// else if (versionNodes[0].value() == null || versionNodes[0].value().toString() == "unspecified") {
// throw Error("${versionNodes[0]}")
// }
}
}
}
}

private fun loadRootVersion(project: Project) { val rootPropertiesFile = File(getRootGradlePropertiesFile(project), "gradle.properties")
val rootProperties = Properties()
if (rootPropertiesFile.exists()) {
rootProperties.load(rootPropertiesFile.inputStream())
Expand All @@ -147,8 +155,11 @@ class LocalMavenPublishPlugin : Plugin<Project> {
}

private fun getRootGradlePropertiesFile(project: Project): File {
if (COMPOSITE_PROJECTS_TO_INCLUDE.contains(project.name)) {
return project.projectDir.parentFile.parentFile
if (COMPOSITE_PROJECTS_TO_INCLUDE.contains(project.name) && project.childProjects.isNotEmpty()) {
return when (project.name) {
"tor", "bitcoind" -> project.projectDir.parentFile.parentFile
else -> project.projectDir.parentFile
}
}
return project.projectDir.parentFile
}
Expand All @@ -157,6 +168,6 @@ class LocalMavenPublishPlugin : Plugin<Project> {
if (COMPOSITE_PROJECTS_TO_INCLUDE.contains(project.name)) {
return project.name
}
return "bisq"
return DEFAULT_GROUP
}
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ tasks.register("publishAll") {
":support:publishToMavenLocal",
":trade:publishToMavenLocal",
":user:publishToMavenLocal",
":wallets:publishToMavenLocal",
":wallets:bitcoind:publishToMavenLocal",
).forEach {
exec {
println("Executing Publish To Maven Local: $it")
Expand Down
4 changes: 2 additions & 2 deletions chat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ dependencies {
implementation(project(":presentation"))
implementation(project(":bonded-roles"))

implementation("network:network")
implementation("network:network-identity")
implementation("network:network:$version")
implementation("network:network-identity:$version")

implementation(libs.chimp.jsocks)
implementation(libs.google.gson)
Expand Down
4 changes: 2 additions & 2 deletions contract/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ dependencies {
implementation(project(":account"))
implementation(project(":offer"))

implementation("network:network")
implementation("network:network-identity")
implementation("network:network:$version")
implementation("network:network-identity:$version")
}
4 changes: 2 additions & 2 deletions identity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ dependencies {
implementation(project(":persistence"))
implementation(project(":security"))

implementation("network:network")
implementation("network:network-identity")
implementation("network:network:$version")
implementation("network:network-identity:$version")

implementation(libs.typesafe.config)
}
15 changes: 14 additions & 1 deletion network/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import java.util.*

// Function to read properties from a file - TODO find a way to reuse this code instead of copying when needed
fun readPropertiesFile(filePath: String): Properties {
val properties = Properties()
file(filePath).inputStream().use { properties.load(it) }
return properties
}

plugins {
java
id("bisq.gradle.maven_publisher.LocalMavenPublishPlugin")
Expand All @@ -10,4 +19,8 @@ tasks.named("clean") {
extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
setProperty("termsOfServiceAgree", "yes")
}
}

val properties = readPropertiesFile("../gradle.properties")
val rootVersion = properties.getProperty("version", "unspecified")
version = rootVersion
6 changes: 4 additions & 2 deletions network/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ plugins {
id("bisq.java-integration-tests")
}

version = rootProject.version

dependencies {
implementation("bisq:common")
implementation("bisq:security")
implementation("bisq:persistence")

implementation(project(":network-identity"))
implementation(project(":i2p"))
implementation("tor:tor")
implementation("tor:tor:$version")

implementation(libs.bouncycastle)
implementation(libs.failsafe)
Expand All @@ -21,4 +23,4 @@ dependencies {
implementation(libs.chimp.jsocks)

integrationTestImplementation(libs.mockito)
}
}
4 changes: 3 additions & 1 deletion network/socks5-socket-channel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugins {
id("bisq.java-library")
id("bisq.java-integration-tests")
}
}

version = rootProject.version
10 changes: 6 additions & 4 deletions network/tor/tor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ plugins {
id("bisq.gradle.tor_binary.BisqTorBinaryPlugin")
}

val properties = readPropertiesFile("../../../gradle.properties")
val bisqVersion: String = properties.getProperty("version", "unspecified")

tor {
val properties = readPropertiesFile("../../../gradle.properties")
val torVersion = properties.getProperty("tor.version", "unspecified")
version.set(torVersion)
}
Expand All @@ -30,10 +32,10 @@ sourceSets {
dependencies {
implementation(project(":tor-common"))

implementation("bisq:security")
implementation("bisq:security:$bisqVersion")

implementation("network:network-identity")
implementation("network:socks5-socket-channel")
implementation("network:network-identity:$bisqVersion")
implementation("network:socks5-socket-channel:$bisqVersion")

implementation(libs.bouncycastle)
implementation(libs.failsafe)
Expand Down
4 changes: 2 additions & 2 deletions offer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies {
implementation(project(":presentation"))
implementation(project(":bonded-roles"))

implementation("network:network")
implementation("network:network-identity")
implementation("network:network:$version")
implementation("network:network-identity:$version")

implementation(libs.google.gson)
implementation(libs.chimp.jsocks)
Expand Down
2 changes: 0 additions & 2 deletions platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,3 @@ dependencies {
}
}
}

//version = rootProject.version
Loading

0 comments on commit 912c078

Please sign in to comment.