From: Gustavo Martin Morcuende Date: Mon, 23 Jan 2017 06:38:02 +0000 (+0100) Subject: gradle BOM file X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=c5332aa811871b09fa0ef96186a65567d37a5fd5;p=JavaForFun gradle BOM file --- diff --git a/SpringJava/Gradle/build-BOM-1.0-SNAPSHOT.gradle b/SpringJava/Gradle/build-BOM-1.0-SNAPSHOT.gradle new file mode 100644 index 0000000..30627b7 --- /dev/null +++ b/SpringJava/Gradle/build-BOM-1.0-SNAPSHOT.gradle @@ -0,0 +1,207 @@ + +// ***************** USING PROPERTIES FOR VERSIONING, WE MANAGE FROM HERE THE SUBPROJECTS' DEPENDENCIES ***************** +project.ext { + + // Compile dependencies + // Spring + springVersion='4.3.0.RELEASE' + // Spring JPA + springJPAVersion='1.10.2.RELEASE' + // Spring Envers + springDataEnversVersion='1.0.2.RELEASE' + hibernateEnversVersion='5.2.1.Final' + // Hibernate + hibernateValidatorVersion='5.2.4.Final' + hibernateEntityManagerVersion='5.2.1.Final' + // QueryDSL + queryDslAptVersion='4.1.3' + // Liquibase or FlyWay + liquibaseVersion='3.5.3' + flyWayVersion='4.0.3' + // Jackson. + jacksonVersion='2.8.1' + // Validation API. JSR-303 + validationAPIVersion='1.1.0.Final' + + // Provided dependencies. + // Provided dependencies are compileOnly in Gradle. Unlike maven they are not included on the test classpath. Gradle sucks?! + servletApiVersion='4.0.0-b01' + + // LOG4J2 dependencies + slf4jVersion='2.7' + log4jCoreVersion='2.7' + jclOverSlf4jVersion='1.7.22' + + // Unit test dependencies + dockerComposeRuleVersion='0.28.1' + mockitoVersion='2.4.1' + junitVersion='4.12' + + // Integration test dependencies + h2DatabaseVersion='1.4.193' + mysqlConnectorVersion='6.0.5' + + // Plugins + queryDslPluginVersion='1.0.7' + dockerComposePluginVersion='0.3.16' + +} + + +// Be aware: I am not using allprojects because the main build.gradle should not create a jar file but it does :( +subprojects { + apply plugin: 'java' + apply plugin: 'idea' + apply plugin: 'jacoco' + apply plugin: 'eclipse' + apply plugin: 'idea' + apply plugin: 'maven-publish' + + targetCompatibility = 1.8 + sourceCompatibility = 1.8 + + + // ***************** COMMON REPOSITORIES FOR DEPENDENCIES ***************** + repositories { + mavenCentral() + maven { url 'https://dl.bintray.com/palantir/releases' } + } + + + + // ***************** PUBLISH TO REPOSITORY ***************** + // Calls javadoc plugin and creates jar with the generated docs + task javadocJar(type: Jar) { + from javadoc + classifier 'javadoc' + } + + // Calls java plugin and creates jar with the sources + task sourceJar(type: Jar) { + from sourceSets.main.java + classifier 'sources' + } + + publishing { + publications { + mavenJava(MavenPublication) { + // Publishes war or jar file depending on whether we are using the war plugin. + if (plugins.withType(WarPlugin)) { + from components.web + } else { + from components.java + } + + // Publishes jar with sources + artifact sourceJar { + classifier 'sources' + } + // Publishes jar with javadoc + artifact javadocJar { + classifier 'javadoc' + } + + pom.withXml { + asNode().dependencies.'*'.findAll() { + it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep -> + dep.name == it.artifactId.text() + } + }.each() { + it.scope*.value = 'compile' + } + } + } + } + repositories { + maven { + credentials { + username project.artifactory_username + password project.artifactory_password + } + + if(project.version.endsWith('-SNAPSHOT')) { + url 'http://artifactory:8888/artifactory/libs-snapshot-local' + } else { + url 'http://artifactory:8888/artifactory/libs-release-local' + } + } + } + } + + + // ***************** COMMON DEPENDENCIES ***************** + dependencies { + // 1/3 Required dependency for log4j 2 with slf4j: binding between log4j2 and slf4j + compile("org.apache.logging.log4j:log4j-slf4j-impl:${slf4jVersion}") + // 2/3 Required dependency for log4j 2 with slf4j: log4j 2 maven plugin (it is the log4j 2 implementation) + compile("org.apache.logging.log4j:log4j-core:${log4jCoreVersion}") + // 3/3 Required dependency for getting rid of commons logging. This is the BRIDGE (no binding) between Jakarta Commons Logging (used by Spring) + // and whatever I am using for logging (in this case I am using log4j 2) See: http://www.slf4j.org/legacy.html + // We need exclusions in every dependency using Jakarta Commons Logging (see Spring dependencies below) + compile("org.slf4j:jcl-over-slf4j:${jclOverSlf4jVersion}") + + + compile("org.springframework:spring-context:${springVersion}") { + exclude group: 'commons-logging', module: 'commons-logging' + } + compile('javax.inject:javax.inject:1') + compile('cglib:cglib:3.2.4') + + + // Unit tests + testCompile("junit:junit:${junitVersion}") + testCompile("org.mockito:mockito-core:${mockitoVersion}") + } + + + // ***************** COMMON PLUGINS ***************** + buildscript { + repositories { + mavenCentral() + maven { url 'https://plugins.gradle.org/m2/' } + } + dependencies { + classpath group: "info.solidsoft.gradle.pitest", name: "gradle-pitest-plugin", version: "1.1.4" + } + } + + // ***************** MANIFEST FILE ***************** + jar { + manifest { + attributes('Implementation-Title': 'Spring JPA Persistence, gradle example', + 'Implementation-Version': version, + 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-By': System.getProperty('user.name'), + 'Built-JDK': System.getProperty('java.version') + ) + } + } + + + // ***************** COVERAGE ***************** + apply plugin: 'jacoco' + apply from: "$rootProject.projectDir/build-test.gradle" + apply from: "$rootProject.projectDir/build-integTest.gradle" + + jacoco { + toolVersion = '0.7.6.201602180812' + reportsDir = file("$buildDir/reports/jacoco") + } + + jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination "${buildDir}/reports/jacoco/" + } + } + + + // ***************** JAVADOC ***************** + javadoc { + source = sourceSets.main.allJava + classpath = configurations.compile + } + +} + diff --git a/SpringJava/Gradle/build.gradle b/SpringJava/Gradle/build.gradle index 1657670..ff91e0e 100644 --- a/SpringJava/Gradle/build.gradle +++ b/SpringJava/Gradle/build.gradle @@ -1,210 +1,7 @@ +allprojects { -// ***************** USING PROPERTIES FOR VERSIONING, WE MANAGE FROM HERE THE SUBPROJECTS' DEPENDENCIES ***************** -project.ext { - - // Compile dependencies - // Spring - springVersion='4.3.0.RELEASE' - // Spring JPA - springJPAVersion='1.10.2.RELEASE' - // Spring Envers - springDataEnversVersion='1.0.2.RELEASE' - hibernateEnversVersion='5.2.1.Final' - // Hibernate - hibernateValidatorVersion='5.2.4.Final' - hibernateEntityManagerVersion='5.2.1.Final' - // QueryDSL - queryDslAptVersion='4.1.3' - // Liquibase or FlyWay - liquibaseVersion='3.5.3' - flyWayVersion='4.0.3' - // Jackson. - jacksonVersion='2.8.1' - // Validation API. JSR-303 - validationAPIVersion='1.1.0.Final' - - // Provided dependencies. - // Provided dependencies are compileOnly in Gradle. Unlike maven they are not included on the test classpath. Gradle sucks?! - servletApiVersion='4.0.0-b01' - - // LOG4J2 dependencies - slf4jVersion='2.7' - log4jCoreVersion='2.7' - jclOverSlf4jVersion='1.7.22' - - // Unit test dependencies - dockerComposeRuleVersion='0.28.1' - mockitoVersion='2.4.1' - junitVersion='4.12' - - // Integration test dependencies - h2DatabaseVersion='1.4.193' - mysqlConnectorVersion='6.0.5' - - // Plugins - queryDslPluginVersion='1.0.7' - dockerComposePluginVersion='0.3.16' + // You could use your gradle 'BOM' file in this way: + // apply from: 'http://artifactory:8888/artifactory/libs-snapshot-local/build-BOM-1.0-SNAPSHOT.gradle + apply from: "$rootProject.projectDir/build-BOM-1.0-SNAPSHOT.gradle" } - - -// Be aware: I am not using allprojects because the main build.gradle should not create a jar file :) -subprojects { - apply plugin: 'java' - apply plugin: 'idea' - apply plugin: 'jacoco' - apply plugin: 'eclipse' - apply plugin: 'idea' - apply plugin: 'maven-publish' - - group 'de.spring.jpa' - version '1.0-SNAPSHOT' - - targetCompatibility = 1.8 - sourceCompatibility = 1.8 - - - // ***************** COMMON REPOSITORIES FOR DEPENDENCIES ***************** - repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/palantir/releases' } - } - - - - // ***************** PUBLISH TO REPOSITORY ***************** - // Calls javadoc plugin and creates jar with the generated docs - task javadocJar(type: Jar) { - from javadoc - classifier 'javadoc' - } - - // Calls java plugin and creates jar with the sources - task sourceJar(type: Jar) { - from sourceSets.main.java - classifier 'sources' - } - - publishing { - publications { - mavenJava(MavenPublication) { - // Publishes war or jar file depending on whether we are using the war plugin. - if (plugins.withType(WarPlugin)) { - from components.web - } else { - from components.java - } - - // Publishes jar with sources - artifact sourceJar { - classifier 'sources' - } - // Publishes jar with javadoc - artifact javadocJar { - classifier 'javadoc' - } - - pom.withXml { - asNode().dependencies.'*'.findAll() { - it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep -> - dep.name == it.artifactId.text() - } - }.each() { - it.scope*.value = 'compile' - } - } - } - } - repositories { - maven { - credentials { - username project.artifactory_username - password project.artifactory_password - } - - if(project.version.endsWith('-SNAPSHOT')) { - url 'http://artifactory/artifactory/libs-snapshot-local' - } else { - url 'http://artifactory/artifactory/libs-release-local' - } - } - } - } - - - // ***************** COMMON DEPENDENCIES ***************** - dependencies { - // 1/3 Required dependency for log4j 2 with slf4j: binding between log4j2 and slf4j - compile("org.apache.logging.log4j:log4j-slf4j-impl:${slf4jVersion}") - // 2/3 Required dependency for log4j 2 with slf4j: log4j 2 maven plugin (it is the log4j 2 implementation) - compile("org.apache.logging.log4j:log4j-core:${log4jCoreVersion}") - // 3/3 Required dependency for getting rid of commons logging. This is the BRIDGE (no binding) between Jakarta Commons Logging (used by Spring) - // and whatever I am using for logging (in this case I am using log4j 2) See: http://www.slf4j.org/legacy.html - // We need exclusions in every dependency using Jakarta Commons Logging (see Spring dependencies below) - compile("org.slf4j:jcl-over-slf4j:${jclOverSlf4jVersion}") - - - compile("org.springframework:spring-context:${springVersion}") { - exclude group: 'commons-logging', module: 'commons-logging' - } - compile('javax.inject:javax.inject:1') - compile('cglib:cglib:3.2.4') - - - // Unit tests - testCompile("junit:junit:${junitVersion}") - testCompile("org.mockito:mockito-core:${mockitoVersion}") - } - - - // ***************** COMMON PLUGINS ***************** - buildscript { - repositories { - mavenCentral() - maven { url 'https://plugins.gradle.org/m2/' } - } - dependencies { - classpath group: "info.solidsoft.gradle.pitest", name: "gradle-pitest-plugin", version: "1.1.4" - } - } - - // ***************** MANIFEST FILE ***************** - jar { - manifest { - attributes('Implementation-Title': 'Spring JPA Persistence, gradle example', - 'Implementation-Version': version, - 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-By': System.getProperty('user.name'), - 'Built-JDK': System.getProperty('java.version') - ) - } - } - - - // ***************** COVERAGE ***************** - apply plugin: 'jacoco' - apply from: "$rootProject.projectDir/build-test.gradle" - apply from: "$rootProject.projectDir/build-integTest.gradle" - - jacoco { - toolVersion = '0.7.6.201602180812' - reportsDir = file("$buildDir/reports/jacoco") - } - - jacocoTestReport { - reports { - xml.enabled false - csv.enabled false - html.destination "${buildDir}/reports/jacoco/" - } - } - - - // ***************** JAVADOC ***************** - javadoc { - source = sourceSets.main.allJava - classpath = configurations.compile - } - -} - diff --git a/SpringJava/Gradle/gradle.properties b/SpringJava/Gradle/gradle.properties new file mode 100644 index 0000000..9b2d48f --- /dev/null +++ b/SpringJava/Gradle/gradle.properties @@ -0,0 +1,2 @@ +group='de.spring.jpa' +version='1.0-SNAPSHOT'