Gradle DSL method not found: 'destination()' after update to Gradle 5.2.1 - gradle

After updating to Gradle 5.2.1 my build is failing with this error:
Gradle DSL method not found: 'destination()'
I figured out that this error has something todo with my analysis.gradle
My analysis.gradle looks like that
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.7.201606060606"
}
check.dependsOn 'checkstyle', 'pmd', 'lint'
task checkstyle(type: Checkstyle) {
println "----- checkstyle -----"
configFile file(projectDir.getAbsolutePath() + '/analysis/checkstyle-ruleset.xml')
source 'src'
source '../domain/src'
source '../util/src'
include '**/*.java'
exclude '**/gen/**'
exclude '**/java-gen/**'
exclude '**/androidTest/**'
exclude '**/test/**'
ignoreFailures = true
classpath = files()
reports {
xml {
destination buildDir.absolutePath + "/outputs/reports/checkstyle_report.xml"
}
}
}
I think I have to replace the destination flag but I have no idea how to replace it.

Before Gradle 5.0 the method setDestination(Object file) was already deprecated, see here : setDestination(Object file)
In Gradle 5.x this method has been removed, you must now use setDestination(File file) which takes a File parameter (see setDestination(File file) )
So you need to change your code into:
reports {
xml {
destination file("$buildDir/outputs/reports/checkstyle_report.xml")
}
}

All adjustment was done in my quality.gradle. Check config folder for quality.gradle file and change all usage of
destination "$reportsDir/pmd/pmd.xml"
to
destination file("$reportsDir/pmd/pmd.html")

Related

Multiple Gradle Files in the same project using apply from

I'm trying to segregate the gradle tasks to respective gradle files.
build.gradle
plugins {
id 'org.openapi.generator' version '4.3.1'
}
apply from: "$projectDir/gradle/script/openapi.gradle"
openapi.gradle
task buildSampleClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "spring"
inputSpec = "$rootDir/src/main/resources/sample.yaml".toString()
outputDir = "$buildDir/generated".toString()
modelPackage = "com.sample"
}
When gradle build is run, getting this error
A problem occurred evaluating script.
Could not get unknown property 'org' for root project 'sample' of type org.gradle.api.Project.
But If I move the content of openapi.gradle into build.gradle it works fine.
Not sure what is the issue, could anyone help here please?
You should add plugin dependencies before your task definition to your openapi.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:${openapiPluginDependencyVersion}"
}
}
apply plugin: "org.openapi.generator"
// your task goes here
task buildSampleClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
...
}
gradle.properties:
openapiPluginDependencyVersion=4.3.0

Gradle: change property of task from a plugin

This is about as basic as it could be... but I haven't found the answer either here or at gradle.org or generally. NB Gradle 4.4.1, Groovy 2.4 (used by Eclipse-Gradle) or 2.6 (command line). Java 8.
In my build.gradle I have the application plugin and have set the main class:
apply plugin: 'application'
mainClassName = "core.ConsoleHandler"
... including this plugin adds 2 "dependency tasks" (if that's the right term: i.e. build is now "dependent" on them): taskZip and taskTar.
Here we see that taskZip is of type Zip... and looking up the doc for this subclass of Task here we see that one of the properties of such a Task is destinationDir... i.e. where the .zip file ends up.
All I want to do is set this to a specific directory.
I've tried (in build.gradle) things like
task application.taskZip {
destinationDir = 'D:/bobble'
}
and
taskZip {
destinationDir = 'D:/bobble'
}
and
destinationDir = 'D:/bobble'
These all produce fatal errors. What should I be doing?
It's distZip not taskZip
apply plugin: 'application'
distZip {
destinationDir = file('D:/bobble')
}
destinationDir takes a File parameter
Try something like that :
tasks.withType(taskZip) {
destinationDir = file("D:/bobble")
}

ScalaStyle using grade return an error

I'm looking for scalaStyle using gradle. Can you explain how to do it?
I've tried this link, but I get an error:
Error:(110, 0) Could not find method scalaStyle() for arguments
[build_5ig236mubh10t6rxyt8apdkfi$_run_closure4#46b9e954] on root
project .....
Here's is a sample build.gradle that uses scalaStyle plugin:
buildscript {
repositories {
maven {
url 'http://jcenter.bintray.com/'
}
}
dependencies {
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.9.0' //version 1.0.0 is not published yet.
}
}
apply plugin: 'scalaStyle'
scalaStyle {
configLocation = '/path/to/scalaStyle.xml'
includeTestSourceDirectory = true
source = 'src/main/scala'
testSource = 'src/test/scala'
}
You need to define buildscript block to declare dependencies for the script itself. When it's done a plugin needs to be applied. Finally you can use scalaStyle block to configure the plugin's behaviour.

Control the gradle task execute order

I have a strange problem about gradle task recently.
Assume I have a simple gradle config as follows
apply plugin: "java"
apply plugin: "maven"
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.diffplug.gradle.spotless:spotless:2.0.0"
}
}
apply plugin: "com.diffplug.gradle.spotless"
spotless {
java {
eclipseFormatFile 'format.xml' // XML file dumped out by the Eclipse formatter
}
}
spotlessJavaCheck.dependsOn(processResources)
version = '1.0-SNAPSHOT'
I just want to set the depends on relationship for the spotless check. After I run a build, the error looks like this
> Could not find property 'spotlessJavaCheck' on root project 'gradle-helloworld'.
I have done something similar with other plugins, it works well, but not for this spotless plugin.
Br,
Tim
Spotless Gradle plugin does magic at configuration time.
You need to set the dependency after evaluation time, once the magic is done:
afterEvaluate {
tasks['spotlessJavaCheck'].dependsOn processResources
}

Not Publishing the mentioned file(war/tar/zip) to artifactory in gradle script

I wrote a gradle script where I am creating the zip and war file and then I need to upload/publish it to the artifactory but the issue is I specified the war file in my artifact task even after that it is publishing everything to the artifactory zip,tar and war instead of only war file.
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'distribution'
//-- set the group for publishing
group = 'com.xxx.discovery'
/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.coveryadBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.coveryadBuildVersion
println "${version}"
//name is set in the settings.gradle file
group = "com.aaa.covery"
version = buildProperties.discoveryadBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"
repositories {
maven {
url "http://cxxxxt.tshaaaaa.tho.com:9000/artifactory/libselease"
}
maven {
url "http://cxxxxt.tshaaa.tho.com:9000/artifactory/cache"
}
}
dependencies {
compile ([
"com.uters.omni:HermesSessionAPI:1.2",
"com.uters.proxy:ProxyResources:1.1",
"com.uters.omni:SeshataDirectory:1.0.1" ,
"com.euters.omni:CybeleInfrastructure:1.1.2",
"com.euters:JSONBus:1.4.1",
"javaee:javaee-api:5"
])
}
distributions {
main {
contents {
from {
war.outputs
}
}
}
}
// for publishing to artifactory
artifacts {
archives war
}
According to gradle distribution plugin documentation:
All of the files in the “src/$distribution.name/dist” directory will automatically be included in the distribution.
And also,
The distribution plugin adds the distribution archives as candidate for default publishing artifacts.
In other words, by default all the files will be published so this explains the behavior you're experiencing.
What you can probably do in order to workaround this behavior is to define the contents copySpec more accurately by explicitly exclude the unwanted files, i.e.:
distributions {
main {
contents {
exclude('**/.zip')
exclude('**/.tar')
from {
war.outputs
}
}
}
}
Note that I didn't try the above by myself though so some fine tuning might be needed. However I believe that you can find the data you need in the CopySpec Interface documentation

Resources