Yamko
Yamko

Reputation: 535

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?

Upvotes: 1

Views: 617

Answers (2)

kike
kike

Reputation: 4463

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")

Upvotes: 0

barfuin
barfuin

Reputation: 17474

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.

Upvotes: 2

Related Questions