Custom Gradle Plugin ID not found

前端 未结 6 562
余生分开走
余生分开走 2020-12-28 13:30

I\'m writing a Gradle plugin and I\'m failing to get the apply plugin: command to work in the Gradle script that uses the plugin. I\'m using Gradle 1.1.

6条回答
  •  旧巷少年郎
    2020-12-28 13:52

    Ensure that your top-level build.gradle uses the correct classpath to refer to the path to the built *.jar file.

    Some plugins, like maven-publish, will build and save the jar to a specific location in mavenLocal, but the path may not be clear to see.

    You should look at the file path of the jar file, and ensure it matches your classpath, but the mapping is not immediately obvious:

    buildscript {
      dependencies {
        // This *MUST* match the local file path of the jar file in mavenLocal, which is:
        // ~/.m2/repository/com/company/product/plugin/product-gradle-plugin/1.0/product-gradle-plugin-1.0.jar
        classpath 'com.company.product.plugin:product-gradle-plugin:1.0'
      }
    }
    

    Be careful not to use the wrong classpath, which can refer to a directory instead of the actual jar file; like this:

    buildscript {
      dependencies {
        // This is wrong, because it refers to the mavenLocal FOLDER "product-gradle-plugin",
        // instead of the jar FILE "product-gradle-plugin-1.0.jar"
        // However, a gradle sync will still resolve it as a valid classpath!!
        classpath 'com.company.product:product-gradle-plugin:1.0'
      }
    }
    

    More info:

    • https://discuss.gradle.org/t/what-is-the-preferred-gradle-approach-to-locally-install-an-artifact-equivalent-to-mavens-install/5592
    • https://docs.gradle.org/current/userguide/publishing_maven.html
    • https://blog.codefx.org/tools/snapshots-gradle-maven-publish-plugin/
    • https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project

提交回复
热议问题