How to apply a Gradle plugin from another plugin?

后端 未结 2 1095
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 08:42

I\'m trying to encapsulate android plugin in my own plugin, but when I\'m trying to apply my plugin build fails with an exception:

A problem occurred evaluating          


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-02-08 08:45

    I guess that at the time You'd like to add the plugin dependencies for the build script have been already resolved, thus it won't work that way. You need to specify the plugin You'd like to apply as a script dependency itself.

    It will work that way:

    buildscript {
       repositories {
          mavenCentral()
       }
    
       dependencies {
          classpath 'com.android.tools.build:gradle:1.0.0-rc1'
       }
    }
    
    
    apply plugin: 'groovy'
    apply plugin: Build
    
    version = '1.0'
    group = 'com.mycomp'
    
    dependencies {
        compile gradleApi()
        compile localGroovy()
    }
    
    import org.gradle.api.Plugin
    import org.gradle.api.Project
    
    class Build implements Plugin {
        void apply(Project project) {
            project.configure(project) {
                apply plugin: 'android-library'
            }
        }
    }
    

    Now, android-plugin is found but it fails because of the fact that groovy plugin had been applied earlier and there's a conflict.

提交回复
热议问题