1

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?

Yamko
  • 535
  • 1
  • 3
  • 13

2 Answers2

2

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.

barfuin
  • 16,865
  • 10
  • 85
  • 132
  • Doesn't work. Maybe I need to try another plugin name? – Yamko Sep 27 '19 at 14:01
  • What do you mean by "doesn't work" - I see this work all the time. Does the idea behind the code snippet make sense to you? Query the plugin manager for the plugins present and deduce the module type from that? – barfuin Sep 27 '19 at 15:28
  • Looks like I need to solve another issue. When my task is being executed only JaCoCo plugin is present and nothing else. – Yamko Oct 02 '19 at 06:35
0

I had a similar situation where I had to distinguish between Android and Java/Kotlin modules.

I used this:
private fun Project.isAndroidModule(): Boolean = this.hasProperty("android")

kike
  • 4,255
  • 5
  • 23
  • 41