自定义 Gradle 插件找不到它自己的 Maven 依赖项

Custom Gradle Plugin cannot find it's own maven dependency

在我的项目中,我想包含一个使用自定义依赖项的 gradle 任务。 为此,我将编写一个自定义 gradle 插件。

但是当我启动gradle时,显示如下错误:

A problem occurred configuring root project 'moduleUpdater'.
Could not resolve all dependencies for configuration ':classpath'.

Could not find org.example.plugin:MyJavaPlugin:1.0-SNAPSHOT.

Searched in the following locations:
         .../moduleUpdater/repo/org/example/plugin/MyJavaPlugin/1.0-SNAPSHOT/maven-metadata.xml
         .../moduleUpdater/repo/org/example/plugin/MyJavaPlugin/1.0-SNAPSHOT/MyJavaPlugin-1.0-SNAPSHOT.pom
        .../moduleUpdater/repo/org/example/plugin/MyJavaPlugin/1.0-SNAPSHOT/MyJavaPlugin-1.0-SNAPSHOT.jar

Required by:           
         :moduleUpdater:unspecified

问题是自定义gradle插件的maven依赖没有添加到主rootProject中。

我使用的教程就像:
Creating a Gradle Custom Plugin with Javahttp://www.javacodegeeks.com/2012/08/gradle-custom-plugin.html

下面的教程创建了一个项目,就像在这个 git-repository 上一样: https://github.com/rakeshcusat/Code4Reference/tree/master/GradleExample/custom-plugin-1

但是,如果我尝试在这个给定存储库的 "user" 文件夹中 运行 "gradle task",我仍然会收到相同的消息:

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'user'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find com.code4reference:code4ReferencePlugin:1.1-SNAPSHOT.
     Searched in the following locations:
         .../Code4Reference-master/GradleExample/custom-plugin-1/repo/com/code4reference/code4ReferencePlugin/1.1-SNAPSHOT/maven-metadata.xml
         .../Code4Reference-master/GradleExample/custom-plugin-1/repo/com/code4reference/code4ReferencePlugin/1.1-SNAPSHOT/code4ReferencePlugin-1.1-20120816.164441-5.pom
         .../Code4Reference-master/GradleExample/custom-plugin-1/repo/com/code4reference/code4ReferencePlugin/1.1-SNAPSHOT/code4ReferencePlugin-1.1-20120816.164441-5.jar
     Required by:
         :user:unspecified

它如何告诉 gradle 自动创建插件的 maven 存储库(使用相同的任务)?

我参考您发布的 github link 回答,因为我们没有您的代码。

user 项目使用插件,但必须先构建插件并将其部署到../repo,然后才能使用它。先去 plugin 项目然后 运行

gradle install

这将构建插件并在文件夹 ../repo

中创建一个 Maven 存储库