Skip to content

Commit 53c4fe1

Browse files
committed
feat: centralize default Log4j version in gradle.properties
The default Log4j version is now defined in `gradle.properties` instead of being hard-coded in build logic. This makes it easier to update or override the version consistently across the build.
1 parent 842887d commit 53c4fe1

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android.useAndroidX = true
2626
# Version of Log4j Core
2727
#
2828
# Default: last stable 2.x release
29-
log4j.version = 2.24.3
29+
log4jVersion = 2.25.1
3030

3131
##
3232
# Staging Maven Repository

log4j-samples-android/app/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ android {
4949
}
5050
}
5151

52-
def log4jVersion = providers.environmentVariable("LOG4J_VERSION").getOrElse("2.+")
53-
5452
dependencies {
5553

5654
implementation 'androidx.appcompat:appcompat:1.7.1'
@@ -63,9 +61,9 @@ dependencies {
6361
androidTestImplementation 'org.assertj:assertj-core:3.27.4'
6462

6563
// Log4j
66-
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion
67-
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4jVersion
68-
androidTestImplementation(group: 'org.apache.logging.log4j', name: 'log4j-core-test', version: log4jVersion) {
64+
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: project.ext.log4jVersion
65+
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: project.ext.log4jVersion
66+
androidTestImplementation(group: 'org.apache.logging.log4j', name: 'log4j-core-test', version: project.ext.log4jVersion) {
6967
exclude group: 'com.google.code.java-allocation-instrumenter'
7068
exclude group: 'org.apache.logging.log4j', module: 'log4j-api-test'
7169
exclude group: 'org.hamcrest'

log4j-samples-gradle-metadata/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ plugins {
1818
id("application")
1919
}
2020

21-
def log4jVersion = providers.environmentVariable("LOG4J_VERSION").getOrElse("2.25.0")
22-
2321
application {
2422
mainModule = "org.example.log4j.metadata"
2523
mainClass = "org.example.App" // see: src/main/java/org/example/App.java
2624
}
2725

2826
dependencies {
29-
implementation("org.apache.logging.log4j:log4j-api:$log4jVersion")
27+
implementation("org.apache.logging.log4j:log4j-api:${project.ext.log4jVersion}")
3028
}
3129

3230
tasks.withType(JavaCompile).configureEach {

settings.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ dependencyResolutionManagement {
4444
}
4545
}
4646
rootProject.name = 'logging-log4j-samples'
47+
def log4jVersion = providers.environmentVariable("LOG4J_VERSION")
48+
.orElse(providers.gradleProperty("log4jVersion"))
49+
.get()
50+
gradle.beforeProject { Project it ->
51+
it.ext.log4jVersion = log4jVersion
52+
}
4753

4854
// Android example
4955
include ':app'

0 commit comments

Comments
 (0)