androidgradleandroid-gradle-pluginjava-moduleandroid-module

Gradle module type


I have multi module project. There are 2 types of modules: Java library(apply plugin: 'java-library') and Android library(apply plugin: 'com.android.library'). I have a custom gradle task and I need somehow to get module type. Which module property do I need to check?


Solution

  • There is no "module type property", but you might ask the plugin manager which plugins have been applied to the project. For example, in order to check if it's a Java project:

    public boolean isJavaProject(final Project pProject)
    {
        PluginManager pluginManager = pProject.getPluginManager();
        return pluginManager.hasPlugin("java") ||
               pluginManager.hasPlugin("org.gradle.java");
    }
    

    The same idea can be applied to check for other plugin types.