Skip to content

Commit

Permalink
create buildSrc for shared Gradle logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kszapsza committed Nov 26, 2024
1 parent 4239405 commit 75bfd4b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build
.gradle
.kotlin
classes
*.iml
*.ipr
Expand Down
28 changes: 10 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent
import pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator
import pl.allegro.tech.hermes.findIntProperty
import pl.allegro.tech.hermes.findLongProperty
import java.time.Duration

plugins {
Expand All @@ -25,8 +27,8 @@ java {
}

nexusPublishing {
connectTimeout = Duration.ofMinutes(getLongProperty("publishingTimeoutInMin", 10))
clientTimeout = Duration.ofMinutes(getLongProperty("publishingTimeoutInMin", 10))
connectTimeout = Duration.ofMinutes(project.findLongProperty("publishingTimeoutInMin", 10))
clientTimeout = Duration.ofMinutes(project.findLongProperty("publishingTimeoutInMin", 10))

repositories {
sonatype {
Expand All @@ -36,8 +38,8 @@ nexusPublishing {
}
}
transitionCheckOptions {
maxRetries = getIntProperty("attemptsToCloseStagingRepository", 30)
delayBetween = Duration.ofSeconds(getLongProperty("delayInSecBetweenCloseStagingRepositoryAttempts", 45))
maxRetries = project.findIntProperty("attemptsToCloseStagingRepository", 30)
delayBetween = Duration.ofSeconds(project.findLongProperty("delayInSecBetweenCloseStagingRepositoryAttempts", 45))
}
}

Expand Down Expand Up @@ -190,18 +192,16 @@ configure(subprojects.filter { it != project(":integration-tests") }) {
}

subprojects {
val versions = rootProject.extra["versions"] as Map<*, *>

configurations.all {
exclude(group = "org.slf4j", module = "slf4j-log4j12")
exclude(group = "log4j", module = "log4j")

resolutionStrategy {
force("org.jboss.logging:jboss-logging:3.2.1.Final")
force("com.google.guava:guava:${versions["guava"] as String}")
force("com.fasterxml.jackson.core:jackson-databind:${versions["jackson"] as String}")
force("com.fasterxml.jackson.core:jackson-annotations:${versions["jackson"] as String}")
force("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:${versions["jackson"] as String}")
force("com.google.guava:guava:${rootProject.libs.versions.guava.get()}")
force("com.fasterxml.jackson.core:jackson-databind:${rootProject.libs.versions.jackson.get()}")
force("com.fasterxml.jackson.core:jackson-annotations:${rootProject.libs.versions.jackson.get()}")
force("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:${rootProject.libs.versions.jackson.get()}")
}
}

Expand All @@ -226,11 +226,3 @@ subprojects {
}
}
}

fun getIntProperty(name: String, defaultValue: Int): Int {
return (project.findProperty(name) as? String)?.toIntOrNull() ?: defaultValue
}

fun getLongProperty(name: String, defaultValue: Long): Long {
return (project.findProperty(name) as? String)?.toLongOrNull() ?: defaultValue
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/pl/allegro/tech/hermes/properties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.allegro.tech.hermes

import org.gradle.api.Project

fun Project.findBooleanProperty(property: String, defaultValue: Boolean): Boolean =
(findProperty(property) as? String)?.toBooleanStrictOrNull() ?: defaultValue

fun Project.findIntProperty(property: String, defaultValue: Int): Int =
(findProperty(property) as? String)?.toIntOrNull() ?: defaultValue

fun Project.findListProperty(property: String, defaultValue: List<String>): List<String> =
(findProperty(property) as? String)?.split(' ') ?: defaultValue

fun Project.findLongProperty(name: String, defaultValue: Long): Long =
(findProperty(name) as? String)?.toLongOrNull() ?: defaultValue

fun Project.findStringProperty(property: String, defaultValue: String): String =
(findProperty(property) as? String) ?: defaultValue
33 changes: 13 additions & 20 deletions hermes-benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import pl.allegro.tech.hermes.findBooleanProperty
import pl.allegro.tech.hermes.findIntProperty
import pl.allegro.tech.hermes.findListProperty
import pl.allegro.tech.hermes.findStringProperty

plugins {
alias(libs.plugins.jmh)
}
Expand All @@ -14,14 +19,14 @@ jmh {
jmhVersion = "1.36"
zip64 = true
verbosity = "NORMAL"
iterations = intProperty("jmh.iterations", 4)
timeOnIteration = stringProperty("jmh.timeOnIteration", "80s")
fork = intProperty("jmh.fork", 1)
warmupIterations = intProperty("jmh.warmupIterations", 4)
warmup = stringProperty("jmh.timeOnWarmupIteration", "80s")
jvmArgs = listProperty("jmh.jvmArgs", listOf("-Xmx1g", "-Xms1g", "-XX:+UseG1GC") + chronicleMapJvmArgs)
failOnError = booleanProperty("jmh.failOnError", true)
threads = intProperty("jmh.threads", 4)
iterations = project.findIntProperty("jmh.iterations", 4)
timeOnIteration = project.findStringProperty("jmh.timeOnIteration", "80s")
fork = project.findIntProperty("jmh.fork", 1)
warmupIterations = project.findIntProperty("jmh.warmupIterations", 4)
warmup = project.findStringProperty("jmh.timeOnWarmupIteration", "80s")
jvmArgs = project.findListProperty("jmh.jvmArgs", listOf("-Xmx1g", "-Xms1g", "-XX:+UseG1GC") + chronicleMapJvmArgs)
failOnError = project.findBooleanProperty("jmh.failOnError", true)
threads = project.findIntProperty("jmh.threads", 4)
synchronizeIterations = false
forceGC = false
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
Expand Down Expand Up @@ -51,15 +56,3 @@ tasks.named<Copy>("processJmhResources") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}

fun stringProperty(property: String, defaultValue: String): String =
(project.findProperty(property) as? String) ?: defaultValue

fun listProperty(property: String, defaultValue: List<String>): List<String> =
(project.findProperty(property) as? String)?.split(' ') ?: defaultValue

fun intProperty(property: String, defaultValue: Int): Int =
(project.findProperty(property) as? String)?.toIntOrNull() ?: defaultValue

fun booleanProperty(property: String, defaultValue: Boolean): Boolean =
(project.findProperty(property) as? String)?.toBooleanStrictOrNull() ?: defaultValue
2 changes: 1 addition & 1 deletion hermes-tracker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies {
implementation(project(":hermes-api"))
implementation(project(":hermes-metrics"))
testImplementation(project(path = ":hermes-test-helper"))
testRuntimeOnly(group = "org.junit.vintage", name = "junit-vintage-engine", version = versions["junit_jupiter"] as String)
testRuntimeOnly(libs.junit.vintage.engine)
}

val testArtifacts: Configuration by configurations.creating
Expand Down

0 comments on commit 75bfd4b

Please sign in to comment.