【问题标题】:Custom Gradle Plugin cannot find it's own maven dependency自定义 Gradle 插件找不到它自己的 maven 依赖项
【发布时间】:2016-04-30 03:20:03
【问题描述】:

在我的项目中,我想包含一个使用自定义依赖项的 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 Java 和 http://www.javacodegeeks.com/2012/08/gradle-custom-plugin.html

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

但是,如果我尝试在这个给定存储库的“用户”文件夹中运行“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 存储库(使用相同的任务)?

【问题讨论】:

  • 请发布您的build.gradle。

标签: maven gradle build.gradle gradle-plugin


【解决方案1】:

我参考你发布的 github 链接来回答,因为我们没有你的代码。

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

gradle install

这会构建插件并在文件夹 ../repo 中创建一个 maven 存储库

【讨论】:

  • 如果您觉得这个答案有用,请使用upvote按钮
  • 谢谢,这正是我所需要的:这个命令和 > gradle uploadArchives 命令是构建和上传插件以及构建根 gradle 项目所必需的。是否还有可能将此过程包含在根项目的另一个 gradle 任务中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-25
  • 1970-01-01
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
相关资源
最近更新 更多