Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify relative path to checkstyle config in root project in gradle 2.2+

I have the following project structure:

project
  checkstyle
    checkstyle.xml
  subproject1
    ...
  subproject2
    ...
  build.gradle

My configuration for checkstyle in the build.gradle is as follows:

allprojects {
  apply plugin: 'checkstyle'
  checkstyle {
    configFile = 'checkstyle/checkstyle.xml' as File
  }
}

When I was using gradle 2.1, build worked OK. After upgrading to 2.2 or 2.2.1 the error occurs:

:subproject1:checkstyleMain FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':subproject1:checkstyleMain'.
> Unable to create a Checker: unable to find /home/my/project/subproject1/checkstyle/checkstyle.xml

Gradle is now looking for 'checkstyle/checkstyle.xml' in the subproject directory, which is not what I would expect.

I have found that they mentioned this change in 2.2 release notes. But they did not tell how to maintain old behavior of resolving that path. How to do this?

I tried using project.file but it does not work too.

like image 470
fracz Avatar asked Jan 30 '15 20:01

fracz


People also ask

How do I add a checkstyle in gradle?

2.1. To use checkstyle in Gradle you have add the plug-in to your build. gradle and provide a config\checkstyle\checkstyle. xml checkstyle configuration file. A detailed example is given in the checkstyle with Gradle exercise.

What is checkstyle in gradle?

The Checkstyle plugin performs quality checks on your project's Java source files using Checkstyle and generates reports from these checks.


1 Answers

in your snippet

allprojects {
  apply plugin: 'checkstyle'
  checkstyle {
    configFile = 'checkstyle/checkstyle.xml' as File
  }
}

you configure the configfile per project to be relative from the subproject you're currently configuring. you can fix this by replacing

checkstyle {
    configFile = 'checkstyle/checkstyle.xml' as File
}

by

checkstyle {
    configFile = rootProject.file('checkstyle/checkstyle.xml')
}
like image 81
Rene Groeschke Avatar answered Oct 19 '22 11:10

Rene Groeschke