gradle - add clover params to each subproject - gradle

I have a gradle based project with numerous subprojects. I want to run clover on all of these but my config seems insistent on having the clover.license file in every subproject folder and a specific clover section in every subproject build file.
How would I specify the clover parama in the main project and have these applied to each subproject?
snip from build.gradle:
apply plugin: 'com.bmuschko.clover'
clover {
licenseLocation = new File(rootDir, 'clover.license')
report {
html = true
}
}
dependencies {
clover 'com.cenqua.clover:clover:3.2.0'
}
Error message from ./gradlew cloverGenerateReport:
service_name:cloverAggregateDatabases FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':service_name:cloverAggregateDatabases'.
java.lang.RuntimeException: Invalid or missing License.. Please visit http://my.atlassian.com to obtain a valid license.

Include this in the buildscript section of the subproject build.gradle files:
dependencies {
classpath 'com.bmuschko:gradle-clover-plugin:2.0.1'
}

Related

Gradle: Invalid publication 'maven': artifact file does not exist

Java 11 and Gradle 7.2 here. I am trying to build a reusable library that I can (eventually) publish to a Maven repository and pull into other projects. But first I just want to get it publishing to my local m2 repo.
The project directory structure looks like:
mylib/
lib/
src/
build.gradle
Where build.gradle is:
plugins {
id 'java-library'
id 'maven-publish'
id 'io.freefair.lombok' version "6.5.0-rc1"
}
sourceCompatibility = 1.11
targetCompatibility = 1.11
archivesBaseName = 'mylib'
version = '1.0.0-RC1'
group = 'org.example'
repositories {
mavenCentral()
}
dependencies {
// omitted for brevity
)
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}
publishing {
publications {
maven(MavenPublication) {
artifact("build/libs/${archivesBaseName}-${version}.jar") {
extension 'jar'
}
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
publishToMavenLocal.configure {
mustRunAfter build
}
When I run gradle publishToMavenLocal I get:
% ./gradlew clean build publishToMavenLocal
> Task :lib:publishMavenPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
> Invalid publication 'maven': artifact file does not exist: '/Users/myuser/workspace/mylib/lib/build/libs/mylib-1.0.0-RC1.jar'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 833ms
6 actionable tasks: 6 executed
So it looks like even though I'm specifying (on the command line) to run clean then build then publishToMavenLocal, and even though I'm even specifying (in build.gradle) that publishToMavenLocal must run after build, it seems what is happening is:
publishToMavenLocal insists on running first (before clean or build)
Since the JAR hasn't been built yet, no JAR file exists at the location specified ("build/libs/${archivesBaseName}-${version}.jar")
The build fails because the artifact doesn't exist
So I think I just need to get build to run before publishToMavenLocal but I'm out of ideas.
You're mixing the plugins DSL (plugins { }) with legacy plugin application (apply plugin). That's not a big deal, but you should go with #sean's answer and use the plugins DSL instead which will solve your issue.
To your problem at hand
Could not get unknown property 'plugin'
That happens because you missed the : in apply plugin
apply plugin: 'maven-publish'
Try placing your plugins in this way. Not sure if that resolves your issue though.
plugins {
id 'java-library'
id 'maven-publish'
}

gradle Could not get unknown property 'war' for project '<project name>' of type org.gradle.api.Project

I have a gradle build with Java sub-projects and had a jacoco task defined in the root build.gradle which I'm moving to the sub-projects that only use it.
By doing that though I am hitting an issue in the ear deploymentDescriptor task where and there are multiple webModule definitions.
The error I'm seeing in the IDE and gradle command line is:
A problem occurred evaluating project ':deployear'.
> Could not get unknown property 'war' for project ':sub-project-two' of type org.gradle.api.Project.
My ear build.gradle contains
apply plugin: 'ear'
ear {
archiveName = 'web-application.ear'
appDirName 'src/main/application'
libDirName 'APP-INF/lib'
deploymentDescriptor {
fileName = "application.xml"
version = "1"
description = "My Web Application"
initializeInOrder = true
displayName = "Web Application"
webModule(project(":sub-project-one").war.archiveName, "context-root/one")
webModule(project(":sub-project-two").war.archiveName, "context-root/two")
}
}
If I comment out webModule(project(":sub-project-two").war.archiveName, "context-root/two") then the project builds successfully.
Both sub-project-one and sub-project-one have java and war plugins applied.
Is there a reason why moving a jacoco dependency from a parent build.gradle to some sub-project build.gradle files would generate this error?
Found a work around.
In my deployear sub-project I added
apply plugin: 'ear'
evaluationDependsOn(':sub-project-two')
and that forced the deployear sub-project to evaluate the sub-project-two project prior to running the ear task.
I thought the same could be done with changing the ordering in the parent settings.gradle but that didn't work for me.

Specifying common plugin for all the subprojects in Gradle Multi Project Build

I have an empty root project and one subproject
rootProject.name = "worder"
include("worder-core")
I want to make kotlin.jvm plugin to be common for all subprojects, build.gradle.kts(worder):
plugins {
id("org.jetbrains.kotlin.jvm") version "1.3.61" apply false
id("idea")
}
subprojects {
apply(plugin = "kotlin")
}
And then I'm trying to add dependencies to subproject, build.gradle.kts(worder-core):
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3")
}
Okay, lets test it:
cd worder
gradle tasks // OK
cd worder-core
gradle tasks // FAILED -> Unresolved reference: implementation
So, why do I have worder-core project configuration failed ? IDEA doesn't complain at all.
full root build script
full subproject build sript

Getting spring boot jar files through gradle

The spring framework wants users to use dependency tools to download the framework, so I am trying to use gradle. I got this sample from their website http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto
buildscript {
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
jar {
baseName = 'root'
version = '0.0.1-SNAPSHOT'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
I saved this to a file called build.gradle. Then in the CMD I went to the directory where the build.gralde file is located and type:
gradle build
It seemed to run fine but towards the building it's not working, here is the last logs I got from the command prompt:
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRepackage'.
Unable to find main class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 9.664 secs
I don't understand this "> Unable to find main class". I only want to get all the jar files and put them inside WEB-INF/lib of my eclipse projects. I am extremely new at gradle. What should I do?
It's not really clear to me, acoording to your comments, what are you trying to achieve, if you don't have a project sources, but for some reason wants to download dependent libraries. Gradle doesn't work this way, all the libraries are dowloded on demand, that means, they are dowloaded then you, for example, try to build your source files.
The exception you get, means, that gradle spring boot plugin's task bootRepackage Didn't find a main class in your project. This main class is mandatory for this task, since the task creates a standalone executable jar.
Sure, it is possble to dowload deps by custom task, like:
task getDeps(type: Copy) {
from sourceSets.main.runtimeClasspath
into 'runtime/'
}
But it seems, that you don't properly understand, how does it work. You should try to read gradle user guide first and let gradle to build your project for you, but not just combine some libs.

Checkstyle gradle Unable to instantiate AvoidConstantAsFirstOperandInConditionCheck when checking style

I have configured my Gradle build script to make use of checkstyle together with the added sventu checkstyle checks, however when I execute the checkstyleMain task, the build fails with the following error:
* What went wrong:
Execution failed for task ':checkstyleMain'.
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate AvoidConstantAsFirstOperandInConditionCheck
This happens even though I have included the checkstyle jar in my build. Below is the relevant parts of my build script:
repositories {
mavenCentral()
maven {
url "http://sevntu-checkstyle.github.com/sevntu.checkstyle/maven2"
}
}
checkstyle {
configFile = new File("etc/config/dev.xml");
toolVersion = "6.8"
}
configurations {
checkstyle
}
dependencies {
checkstyle "com.github.sevntu.checkstyle:sevntu-checks:1.13.4"
}
Note that the build works when I remove the dependencies section and test with a checkstyle xml doc that does not have the extra sevntu checks configured. My configuration is also similar to the example at sevntu-checkstyle/checkstyle-samples
What am I missing here?
So I finally figured it out:
Turns out the example at https://github.com/sevntu-checkstyle/checkstyle-samples/blob/master/gradle-project/build.gradle only works if you put the full classpath of the custom checks as the name for each custom check.
This is due to checkstyle not knowing where the custom checks are located in the package. Turns out checkstyle can find this out if you include a checkstyle_packages.xml file in the jar that describes the packages that contains the checks.
Unfortunately there is no such file in com.github.sevntu.checkstyle:sevntu-checks:1.13.4. To get this information, you also need to include "com.github.sevntu.checkstyle:sevntu-checkstyle-maven-plugin:1.13.4", which basically contains nothing but the checkstyle_packages.xml file.
So I've added this to my dependencies and the checkstyle rules finally parses:
dependencies {
checkstyle "com.github.sevntu.checkstyle:sevntu-checks:1.13.4",
"com.github.sevntu.checkstyle:sevntu-checkstyle-maven-plugin:1.13.4"
}
Hoping this will save someone some pain in future :)

Resources