From 2e8e3ba51b64b2021786b58d1825a79dcba68016 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Tue, 21 Jun 2022 19:26:14 +0100 Subject: [PATCH] [JAVA-12742] Fix Gradle parent modue to work with Gradle 7.x --- gradle/README.md | 1 - gradle/build.gradle | 10 +++++--- gradle/gradle-dependency-management/README.md | 4 +++ .../settings.gradle | 2 +- gradle/gradle-employee-app/build.gradle | 15 ++++++----- gradle/gradle-employee-app/settings.gradle | 1 + .../settings.gradle | 1 + gradle/gradletaskdemo/build.gradle | 25 ++++++++----------- .../gradletaskdemo/build/tmp/jar/MANIFEST.MF | 2 -- gradle/greeter/build.gradle | 8 +++--- gradle/greeting-library-java/build.gradle | 6 ++--- gradle/greeting-library/build.gradle | 4 +-- gradle/settings.gradle | 2 -- 13 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 gradle/gradle-dependency-management/README.md create mode 100644 gradle/gradle-employee-app/settings.gradle create mode 100644 gradle/gradle-source-vs-target-compatibility/settings.gradle delete mode 100644 gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF diff --git a/gradle/README.md b/gradle/README.md index 149da50f92..1c325cf2fe 100644 --- a/gradle/README.md +++ b/gradle/README.md @@ -6,4 +6,3 @@ This module contains articles about Gradle - [Introduction to Gradle](https://www.baeldung.com/gradle) - [Writing Custom Gradle Plugins](https://www.baeldung.com/gradle-create-plugin) - [A Custom Task in Gradle](https://www.baeldung.com/gradle-custom-task) -- [Dependency Management in Gradle](https://www.baeldung.com/gradle-dependency-management) diff --git a/gradle/build.gradle b/gradle/build.gradle index 2e5d984fba..d808f4a3cc 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -1,12 +1,14 @@ +plugins { + id 'org.shipkit.bintray-release' version '2.3.5' +} + allprojects { repositories { - jcenter() + mavenCentral() } } - subprojects { - version = '1.0' } @@ -89,4 +91,4 @@ task printJavaVersionBuildSrc(type : PrintToolVersionBuildSrcTask) { task printGroovyVersionBuildSrc(type : PrintToolVersionBuildSrcTask) { tool 'groovy' -} \ No newline at end of file +} diff --git a/gradle/gradle-dependency-management/README.md b/gradle/gradle-dependency-management/README.md new file mode 100644 index 0000000000..60ac66aa87 --- /dev/null +++ b/gradle/gradle-dependency-management/README.md @@ -0,0 +1,4 @@ +### Relevant Articles: + +- [Dependency Management in Gradle](https://www.baeldung.com/gradle-dependency-management) + diff --git a/gradle/gradle-dependency-management/settings.gradle b/gradle/gradle-dependency-management/settings.gradle index 09bfe08af7..b2be0dced7 100644 --- a/gradle/gradle-dependency-management/settings.gradle +++ b/gradle/gradle-dependency-management/settings.gradle @@ -1 +1 @@ -rootProject.name = 'dependencymanagement' +rootProject.name = 'gradle-dependency-management' diff --git a/gradle/gradle-employee-app/build.gradle b/gradle/gradle-employee-app/build.gradle index b343d2b210..c7040504f1 100644 --- a/gradle/gradle-employee-app/build.gradle +++ b/gradle/gradle-employee-app/build.gradle @@ -6,10 +6,8 @@ plugins { apply plugin: 'application' mainClassName = 'employee.EmployeeApp' -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 println 'This is executed during configuration phase' @@ -17,20 +15,21 @@ task configured { println 'The project is configured' } -task wrapper(type: Wrapper){ +wrapper { gradleVersion = '5.3.1' } repositories { - jcenter() + mavenCentral() } dependencies { - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' + implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' testImplementation('junit:junit:4.13') - testRuntime('junit:junit:4.13') + testRuntimeOnly('junit:junit:4.13') } + test { useJUnit() } diff --git a/gradle/gradle-employee-app/settings.gradle b/gradle/gradle-employee-app/settings.gradle new file mode 100644 index 0000000000..c6749f9e68 --- /dev/null +++ b/gradle/gradle-employee-app/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gradle-employee-app' diff --git a/gradle/gradle-source-vs-target-compatibility/settings.gradle b/gradle/gradle-source-vs-target-compatibility/settings.gradle new file mode 100644 index 0000000000..0d985fb082 --- /dev/null +++ b/gradle/gradle-source-vs-target-compatibility/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gradle-source-vs-target-compatibility' diff --git a/gradle/gradletaskdemo/build.gradle b/gradle/gradletaskdemo/build.gradle index 58dadd7460..5f07573365 100644 --- a/gradle/gradletaskdemo/build.gradle +++ b/gradle/gradletaskdemo/build.gradle @@ -5,16 +5,14 @@ buildscript { } } dependencies { - classpath "org.shipkit:shipkit:0.9.117" + classpath "org.shipkit:shipkit:2.3.5" } } - plugins { id 'java' } - apply from: 'aplugin.gradle' apply plugin: 'org.shipkit.bintray-release' @@ -72,8 +70,6 @@ helloBaeldung { } - - //Adding extra task properties task ourTask { ext.theProperty = "theValue" @@ -86,25 +82,24 @@ task printTaskProperty { } - //Declaring dependencies dependencies { - compile group: + implementation group: 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE' - compile 'org.springframework:spring-core:4.3.5.RELEASE', + implementation 'org.springframework:spring-core:4.3.5.RELEASE', 'org.springframework:spring-aop:4.3.5.RELEASE' - compile( + implementation( [group: 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'], [group: 'org.springframework', name: 'spring-aop', version: '4.3.5.RELEASE'] ) - testCompile('org.hibernate:hibernate-core:5.2.12.Final') { + testImplementation('org.hibernate:hibernate-core:5.2.12.Final') { transitive = true } - runtime(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final') { + runtimeOnly(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final') { transitive = false } - runtime "org.codehaus.groovy:groovy-all:2.4.11@jar" - runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar' - - compile fileTree(dir: 'libs', include: '*.jar') + runtimeOnly "org.codehaus.groovy:groovy-all:2.4.11@jar" + runtimeOnly group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar' + + implementation fileTree(dir: 'libs', include: '*.jar') } diff --git a/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF b/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF deleted file mode 100644 index 59499bce4a..0000000000 --- a/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/gradle/greeter/build.gradle b/gradle/greeter/build.gradle index 6f43f23494..0aab8c2313 100644 --- a/gradle/greeter/build.gradle +++ b/gradle/greeter/build.gradle @@ -1,11 +1,11 @@ apply plugin : 'java' apply plugin : 'application' - - dependencies { - compile project(':greeting-library') - compile project(':greeting-library-java') + implementation project(':greeting-library') + implementation project(':greeting-library-java') + + implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar' } mainClassName = 'greeter.Greeter' diff --git a/gradle/greeting-library-java/build.gradle b/gradle/greeting-library-java/build.gradle index 34931bd0cd..916a9a435e 100644 --- a/gradle/greeting-library-java/build.gradle +++ b/gradle/greeting-library-java/build.gradle @@ -1,9 +1,7 @@ apply plugin :'java' //apply plugin : 'application' - - dependencies{ - compile group: 'joda-time', name: 'joda-time', version: '2.9.9' - testCompile group: 'junit', name: 'junit', version: '4.12' + implementation group: 'joda-time', name: 'joda-time', version: '2.9.9' + testImplementation group: 'junit', name: 'junit', version: '4.12' } diff --git a/gradle/greeting-library/build.gradle b/gradle/greeting-library/build.gradle index eb526b3b03..a8fa91963c 100644 --- a/gradle/greeting-library/build.gradle +++ b/gradle/greeting-library/build.gradle @@ -1,9 +1,9 @@ apply plugin : 'groovy' dependencies { - compile 'org.codehaus.groovy:groovy:2.4.12' + implementation 'org.codehaus.groovy:groovy:2.4.12' - testCompile 'org.spockframework:spock-core:1.0-groovy-2.4', { + testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4', { exclude module : 'groovy-all' } } diff --git a/gradle/settings.gradle b/gradle/settings.gradle index aeb462045d..ba255f25c2 100644 --- a/gradle/settings.gradle +++ b/gradle/settings.gradle @@ -4,7 +4,5 @@ include 'greeting-library' include 'greeting-library-java' include 'greeter' include 'gradletaskdemo' -include 'gradle-employee-app' -include 'gradle-source-vs-target-compatibility' println 'This will be executed during the initialization phase.'