【问题标题】:Gradle installing/using a plugin jar locallyGradle 在本地安装/使用插件 jar
【发布时间】:2021-03-04 12:38:29
【问题描述】:

在我的项目中,我有一个必须在本地访问的专有 jar。我试图按照官方指南找出在本地 maven 存储库中安装 jar 的不同方法。

https://docs.gradle.org/current/userguide/publishing_maven.html

但它不起作用。

我做了一个build.gradle文件如下,

plugins {
    id 'maven-publish'
}

project.afterEvaluate {
    publishing {
        publications {
            maven(MavenPublication) {
                groupId = 'com.xxx.yyy.zzz'
                artifactId = 'XYZ'
                version = 'X.X.X'

                from components.java
            }
        }
    }
}

在项目 settings.gradle.kts 中,jar 被获取,

plugins {
    id("com.xxx.yyy.zzz.XYZ") version "X.X.X"
}

现在,在 maven 中,我曾经通过提及 jar 名称将 jar 安装到本地存储库。

由于我是新手,可能我错过了一些重要的理解。

执行命令gradle publishToMavenLocal后出现错误,

gradle publishToMavenLocal

FAILURE: Build failed with an exception.

* Where:
Build file '/home/xxx/yyy/zzz/build.gradle' line: 13

* What went wrong:
A problem occurred configuring root project 'zzz'.
> Exception thrown while executing model rule: PublishingPlugin.Rules#publishing(ExtensionContainer)
   > Could not get unknown property 'java' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

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

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

如果我删除 from components.java 行,则构建成功,但找不到 jar 位置,当我执行主项目构建时,它会显示,

* What went wrong:
Plugin [id: 'com.xxx.yyy.zzz.XYZ', version: 'X.Y.Z'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.xxx.yyy.zzz.XYZ:X.Y.Z')
  Searched in the following repositories:
    MavenLocal(file:/home/xxx/.m2/repository)
    MavenRepo

更新

原来的settings.gradle.kts是,

pluginManagement {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    plugins {
    }
}
plugins {
    id("com.xxx.yyy.zzz.XYZ") version "X.Y.Z"
}

rootProject.name = "svoc-sherlock"

apply(from = "${rootProject.projectDir}/gradle/buildcache.settings.gradle.kts")

include(
    "java-platform",
    "datamodel",
    "lib-common",
    "stream-app-auto-quote-ingestion",
    "stream-app-msiclient-ingestion",
    "stream-app-msianb-quotes-ingestion"
)

【问题讨论】:

  • 您是否尝试将id 'java' 添加到id 'maven-publish' 下方或上方的插件块中
  • @DavidKroukamp 这有效并解决了错误。但是在我访问插件的主项目中,它仍然是相同的(构建错误)。

标签: java maven gradle


【解决方案1】:

在您的 build.gradle 中试试这个:

plugins {
    id 'java'
    id 'maven-publish'
}

这只是添加了同样需要的java插件。

更新

针对您的评论: 您需要在settings.gradle 上添加此行:

rootProject.buildFileName = 'build.gradle.kts' 以上include ':app'

【讨论】:

  • 请查看更新后的问题。我已经添加了(主)构建文件。
  • 那么您是否尝试过添加我建议的行?也许低于rootProject.name
  • 是的。但没有变化。
  • 不是问题。感谢您的宝贵时间。
猜你喜欢
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多