【问题标题】:Gradle Plugin Publishing Plugin with androidGradle Plugin Publishing Plugin with android
【发布时间】:2016-01-15 15:08:05
【问题描述】:

我正在开发一个基于 Android 项目的自定义 gradle 插件。我想通过另一个插件(https://plugins.gradle.org/docs/publish-plugin)发布我的插件,这是我的 build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: "com.gradle.plugin-publish"

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath "com.gradle.publish:plugin-publish-plugin:0.9.3"
    }
}

repositories {
    jcenter()
}

group = 'com.myplugin'
version = '1.0-SNAPSHOT'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri('../repo'))
        }
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 19
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile gradleApi()
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

pluginBundle {
    website = 'http://www.example.com/'
    description = 'Welcome to bla bla'
    tags = ['test', 'test']
    plugins {
        PluginName {
            id = 'com.something'
            displayName = 'My Plugin'
        }
    }
}

当我运行这个时:

./gradlew uploadArchives

我收到此错误:

Parallel execution with configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'mylib'.
> The 'java' plugin has been applied, but it is not compatible with the Android plugins.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.543 secs

【问题讨论】:

  • 显然 plugin-publish 插件正在添加 java 插件,而您添加的 android 插件不喜欢该插件。我会认为他们是不相容的。不过我很好奇 - 如果你不打算构建一个 android lib/app,为什么你的插件项目有 android 插件?
  • 我实际上是在创建一个android lib
  • 那么它是一个 android lib 还是一个 gradle 插件?一个gradle插件将被打包为一个jar,我想一个android lib会是aar?您如何为插件创建一个单独的项目,这取决于您的 android lib,但只是一个 java(或 groovy)项目?
  • 对不起。它是一个依赖于 android 插件的 gradle 插件。这意味着在我的代码中我使用 android 类。我不想创建一个 jar。
  • 因为我在我的 gradle 插件中使用了 android 类

标签: java android maven plugins gradle


【解决方案1】:

对不起,我真正想做的描述在这里:

http://code.tutsplus.com/tutorials/creating-and-publishing-an-android-library--cms-24582

发布我的 android 库,以便任何人都可以通过 gradle 访问它

【讨论】:

  • 在这种情况下,您真正​​需要的是maven-publish 插件,而不是plugin-publish。此外,根据您要上传到哪个仓库,您可能需要 artifactory 或 bintray 插件
  • plugin-publish 插件用于创建像android 插件这样的插件
猜你喜欢
  • 2012-04-10
  • 2011-08-30
  • 2022-12-05
  • 1970-01-01
  • 2016-03-05
  • 2022-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多