How to exclude a module for checkstyle in a multi-module project - gradle

I have a multi-module composite build project.
The project structure is this:
Panda. // Root project
-PandaService. // Service module
-PandaDataAccessLayer // DAL module whose code are generated with JOOQ
I want to exclude PandaDataAccessLayer module for checkstyle, because its code are generated automatically with JOOQ.
My checkstyle.xml is located at Panda/config/checkstyle/checkstyle.xml, and here is the build.gradle in my root project Panda:
repositories {
mavenCentral() // Use Maven Central for resolving dependencies.
}
subprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '10.7.0'
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
checkstyleMain.exclude '**/PandaDataAccessLayer/**'
}
sourceCompatibility = '11'
targetCompatibility = '11'
}
I can see that checkstyle is running with ./gradlew build. However, the generated report still shows that it checks code in PandaDataAccessLayer module.
Checkstyle rule violations were found. See the report at:file:///****/panda/PandaDataAccessLayer/build/reports/checkstyle/main.html
How can I exclude the PandaDataAccessLayer completely from checkstyle?

Related

gradle does not fetch dependencies after upgrade from 5.1.1 to 6.4.1

I have several services that uses gradle 5.1.1 with java 8.
As we want to upgrade to Java 13, we first need to upgrade to gradle 6after doing so, some dependencies are not fetched.
Those dependencies are listed with compile() under a dependency which is our jar library and still built with gradle 5.1.1
our libraries are stored in a S3 bucket and we use shadowjar to generate the end jar.
so, for example:
I have project A which I want to upgrdae.
Project A has project B as a dependency (compile)
Project B has google guava as a dependency (also with compile)
Now, project A, that under gradle 5.1.1 had fetched guava with no problems, alerting me that it is missing guava after upgrading to gradle 6.
I use local computer installed gradle (not wrapper).
Here are the important build.gradle parts:
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
ext.ver = [
'springboot': '2.2.0.RELEASE',
'slf4j' : '1.7.12'
]
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${ver.springboot}"
classpath 'io.spring.gradle:dependency-management-plugin:1.0.7.BUILD-SNAPSHOT'
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
classpath 'com.amazonaws:aws-java-sdk-core:1.11.5'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
}
configurations {
compile.exclude module: 'spring-boot-starter-logging'
testCompile.exclude module: 'spring-boot-starter-logging'
runtime.exclude module: 'spring-boot-starter-logging'
compile.exclude group: 'ch.qos.logback'
}
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 10, 'seconds'
resolutionStrategy.cacheChangingModulesFor 10, 'seconds'
}
dependencyManagement {
applyMavenExclusions = false
}
repositories {
mavenLocal()
maven {
url "s3://bucket"
credentials(AwsCredentials) {
accessKey = awsCredentials.AWSAccessKeyId
secretKey = awsCredentials.AWSSecretKey
}
metadataSources {
artifact()
}
}
mavenCentral()
}
dependencies {
compile("com.test:projectB:1.0.0")
...
}
import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer
shadowJar {
classifier = ''
baseName = 'project-A'
manifest {
attributes 'Main-Class': 'com.test.projectA.Starter'
}
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories']
mergeStrategy = "append"
}
}
Could this be because project B was not built with new gradle?
unfortunately, I cannot create a real reproducer as those libraries are real code of the company I work at.
Thanks and Regards,
Ido
The metadataSources declaration of the s3 bucket Maven repository is most likely the root cause why transitive dependencies of projectB are not resolved. The documentation is quite a bit vague here, but I suspect artifact() looks for the actual jar file only and not for the POM file, hence transitive dependency resolution is not performed. You should be able to see this behavior when running the build with switches --info and --refresh-dependencies.
Thankfully, this is quite easy to fix. Add mavenPom() and Gradle will try to resolve the POM first and with that, dependency resolution should be back to normal.
And while you're at it, you might want to read the upgrading from Gradle 5 guide and get rid of the compile configuration in favor of implementation. You should be able to see a warning similar to this when running the build with --warning-mode all:
The compile configuration has been deprecated for dependency declaration. This will fail with an error in Gradle 7.0. Please use the implementation or api configuration instead. Consult the upgrading guide for further information: https://docs.gradle.org/6.4.1/userguide/upgrading_version_5.html#dependencies_should_no_longer_be_declared_using_the_compile_and_runtime_configurations

spring boot jar missing project dependencies

I have a Spring Boot project that is built using Gradle. It has compile dependencies on other projects. All the projects are mentioned via "includeFlat" in a settings.gradle file in a master project.
My problem: the boot ("fat") jar that is generated by the build omits the project dependencies.
Here's the project structure:
master
(no source)
build.gradle - applies 'Eclipse' plugin (but not Java)
settings.gradle -- has 'includeFlat' for projectA, projectB
projectA
src/main/java/...
build.gradle
projectB
src/main/java/...
build.gradle -- see below
The build.gradle for projectB looks roughly like this:
buildscript
{
repositories
{
mavenCentral()
}
dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar
{
baseName = 'xxx'
version = '0.1.0'
}
repositories
{
mavenCentral()
}
jar {
enabled = true
}
dependencies
{
compile project(":projectA")
}
"gradle build" on projectB generates both a regular and a boot jar. I expect the boot jar to include the classes from ":projectA" -- but they are missing.
Other than that, both projects build and run properly, whether built individually or via the master project.

Gradle multi Project - apply plugin: spring-boot issue

I started working on Gradle multi project and I have the project structure like
Parent
build.gradle
Project A
build.gradle
Project B
build.gradle
I am trying to use spring-boot for that I have added apply plugin: 'spring-boot' in Parent Gradle but i am getting Plugin with id 'spring-boot' not found. I placed the apply plugin in Project A and deleted in Parent but still the same issue. If I separate the Project A from Parent project and run as new individual project it's working fine but not working in case of multi project.
If I delete apply plugin: 'spring-boot' from total project it gives Could not find method compile() for arguments [org.springframework.boot:spring-boot-starter-web] on root project 'Project A'. Appreciate your help on this. Thanks.
EDITED
Added my Gradle files here
Parent Project
group 'com.mydomain'
version '1.0-SNAPSHOT'
buildscript {
repositories{
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'spring-boot'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
}
Project A
group 'com.mydomain'
version '1.0-SNAPSHOT'
// I added dependencies and apply plug-in here but got same issue
Project B
group 'com.mydomain'
version '1.0-SNAPSHOT'
Parent Settings.gradle
rootProject.name = 'Parent'
include 'Project A'
include 'Project B'

How to configure Gradle to find local SNAPSHOT resource?

I'm trying to do some work with the springfox project which has been broken up into two separate projects: the springfox runtime, and a suite of demos.
In order to investigate the behavior of certain configurations, I need to change the module in springfox/springfox-petstore, and compile that into springfox-demos/springfox-java-swagger.
In springfox, I built and published a new version of springfox-petstore, and validated that it exists correctly in ~/.m2/repository/io/springfox/springfox-petstore/2.2.2-SNAPSHOT.
Next, in springfox-demos I added mavenLocal() as a repository, and added the springfox-petstore-2.2.2-SNAPSHOT as a changing=true dependency.
When I attempt to build the springfox-demos runtime, I get the following error:
* What went wrong:
A problem occurred configuring project ':spring-java-swagger'.
> Could not resolve all dependencies for configuration ':spring-java-swagger:runtimeCopy'.
> Could not find io.springfox:springfox-petstore:2.2.2-SNAPSHOT.
Searched in the following locations:
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
Required by:
springfox-demos:spring-java-swagger:unspecified
I've tried a variety of combinations of build tasks but I can't seem to get Gradle to honor my request for using the local maven repo with a -SNAPSHOT artifact.
Here is the top-level build.gradle:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "com.github.adrianbk:gradle-jvmsrc-plugin:0.6.1"
classpath 'com.ofg:uptodate-gradle-plugin:1.6.0'
}
}
apply from: "$rootDir/gradle/dependencies.gradle"
subprojects {
apply plugin: 'com.github.adrianbk.jvmsrc'
jvmsrc {
packageName "springfoxdemo"
}
apply plugin: 'java'
apply plugin: 'com.ofg.uptodate'
repositories {
jcenter()
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
configurations.all {
//Dont cache snapshots
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
wrapper {
gradleVersion = "2.4"
}
So it appears that the top-level build.gradle can have more than one repositories{} block. I had correctly added the mavenLocal() to one, but missed the other. Once adding the mavenLocal() to the second block, all worked well.

How to force artifact/module name with Gradle build

Please note: even though this question specifically mentions Bamboo CI and the Gradle ShadowJar plugin, I believe this is a basic Gradle config question at heart, and believe it can be answered by any battle-weary Gradle Guru.
I have a Groovy app that is built with Gradle, where build.gradle is:
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'eclipse'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
group = 'com.me.myapp'
mainClassName = "com.me.myapp.MyAppDriver"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.0'
}
}
dependencies {
// Omitted for brevity
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}
repositories {
mavenLocal()
mavenCentral()
}
shadowJar {
classifier = ''
mergeServiceFiles {
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
}
artifacts {
archives(file("${buildDir}/libs/myapp-${version}.jar")) {
name "myapp"
classifier ""
builtBy shadowJar
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
And where gradle.properties is:
group=com.me.myapp
version=1.0.0
As you can see, I'm using ShadowJar to produce a self-contained "fat JAR" for my app. When I run gradle clean build shadowJar on my local machine, Gradle produces a build/libs/myapp-1.0.0.jar artifact/archive. However, when this same command is ran from our CI server (Bamboo), Gradle produces a build/libs/MYAPP-KEY-1.0.0.jar artifact/archive, where MYAPP-KEY is the Bamboo "build key" (essentially, a unique key/label identifying the build on the server). If you're clueless as to what I'm talking about, I don't think that really matters. What is important to understand is that Bamboo will check out the source code for myapp to a folder named MYAPP-KEY on the CI server. So locally myapp/ is the root of my project, but on CI MYAPP-KEY is the root of my project.
The main point is that I am not explicitly defining something in my Gradle config, and so it seems that Gradle is using the name of the project root to produce the name of the built JAR. What is this "something" and how/where do I define it? The desired end objective is to produce a build/libs/myapp-1.0.0.jar both locally and on CI.
please, look at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
you can specify base name or full archive name of jar
add it to your jar section

Resources