Skip to content

Plugin for Android Studio that can collect and show code metric infromation from Gradle plugins, such as PMD, Checkstyle

License

Notifications You must be signed in to change notification settings

DrakkLord/gradle-android-metric-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set of plugins for Android Studio that add the functionality to show reports from gradle metric tasks, such as PMD and Checkstyle, the main plugin adds the ability to run a task that will execute the appropriate gradle tasks and parse their output and show it in Android Studio.


  1. Requirements
  2. Installation
  3. Usage
  4. How to build
  5. Contributor API

Image of and example output

  • Android Studio version 3.0 or newer is required!
  • Gradle version 4.0 or newer is required! It doesn't matter if gradle is being used from wrapper or globally installed but it must be 4.0 or newer.
  • at least one contributor plugin must be installed, see installation section for details
  • because gradle metric tasks are being used in order for the plugin to report anything the project being used must have at least one project with PMD or Checkstyle plugin applied and the corresponding contributor plugin installed in Android Studio, see usage for details

You can install the pugins from the jetbrains repository within Android Studio : https://www.jetbrains.com/help/idea/installing-updating-and-uninstalling-repository-plugins.html

In Android Studio search for the following names and install them:

You can verify that you you have completed the installation correctly by checking:

  • you should see 2 new menu items under 'Analyze':
    • 'Get code metrics report'
    • 'Code metrics plugin status'
  • click on menu -> 'Analyze' -> 'Code metrics plugin status', this will show you a window that either shows you errors or shows you what contributor plugins you have installed

The plugin requires your project to have at least one project with one gradle metric plugin such as PMD or Checkstyle

IMPORTANT

Dynamic resolution of the configuration is NOT supported, for example setting the destination from a variable won't be recognised by the plugin and it will revert to the default folder, workaround is to use string literals.

def variable = "$buildDird/whatever.html"
checkstyleTask {
  reports {
    html {
      destination variable // plugin won't be able to use this
      destination "reports/checkstyle/whatever.html" // this is okay
    }
  }
}

You can add PMD and Checkstyle to your gradle project by:

apply plugin: 'checkstyle'
apply plugin: 'pmd'

checkstyle {
    toolVersion = '8.1' // optionally specify tool version
}

pmd {
    toolVersion = '5.8.1' // optionally specify tool version
}

tasks.withType(Checkstyle) {
    ignoreFailures = true // REQUIRED because the plugin will report only up to the point the first issue if this is not set
    showViolations = false
    
    reports {
        xml.enabled = true  // REQUIRED the plugin parses xml reports so this is essential
    }
    
    include '**/*.java'
}

tasks.withType(Pmd) {
    ignoreFailures = true // REQUIRED because the plugin will report only up to the point the first issue if this is not set

    reports {
        xml.enabled = true  // REQUIRED the plugin parses xml reports so this is essential
    }

    include '**/*.java'
}

After this you can verify that the reporting works in gradle by executing:

gradle pmd checkstyle

the default output of the check tools is projectDirectory/build/reports/pmd/ and projectDirectory/build/reports/checkstyle/ respectively.

Now open your project in Android Studio and click on menu > 'Analyze' > 'Get code metrics report', this will execute the appropriate gradle tasks and when they are done open a menu with the results. You should see either 'no issues' or a list of issues, ideally you should see the same errors as you see in the xml files generated by manually running the tasks.

IntelliJ IDEA Community and an Android Studio version 3.0 or newer installation is required for building.

  • open the project in IntelliJ
  • setup a plugin SDK that points to the Android Studio installation
  • make sure that the plugin SDK uses the JDK from the Android Studio installation, you may have to make a JDK configuration first to be able to set it for the plugin SDK
  • you need to set the following additional jar's in the plugin SDK's classpath :
    • Android Studio/plugins/android/lib/artwork.jar
    • Android Studio/plugins/android/lib/android.jar
    • Android Studio/plugins/android/lib/build-common.jar
    • Android Studio/plugins/gradle/lib/gradle-tooling-extension-api.jar
    • Android Studio/gradle/gradle-4.1/lib/gradle-tooling-api-4.1.jar
    • Android Studio/plugins/gradle/lib/gradle.jar
    • Android Studio/gradle/gradle-4.1/lib/plugins/gradle-code-quality-4.1.jar
    • Android Studio/gradle/gradle-4.1/lib/plugins/gradle-reporting-4.1.jar
    • Android Studio/gradle/gradle-4.1/lib/gradle-core-4.1.jar
    • Android Studio/gradle/gradle-4.1/lib/gradle-base-services-groovy-4.1.jar
  • at this point the plugin should compile
  • for testing and debugging you can make run configurations for each of the 3 plugins, in order to get a working environemnt first start the core plugin, then close Android Studio then switch to one of the contributor plugins and start with that. This way you can install the plugins into the test environment.

The main plugin does not include any implementation for specific gradle metric plugins, instead it exposes a 'Contributor API' which simply allows individual plugins to handle the specific gradle metric plugins.

GradleMetricContributor - contributor plugin interface

GradleMetricCheckstyleContributor - implementation of the interface for checkstyle

With this you can implement your own contributor plugin if needed for your own custom gradle metric report tasks.

Releases

No releases published

Packages

No packages published

Languages