[英]Gradle to add module dependency in Micronaut project
I have three module as shown below我有三个模块,如下所示
The fete-bird-apigateway
depend on common and fete-bird-product
depend on both fete-bird-apigateway
and common
fete-bird-apigateway
依赖于 common 并且fete-bird-product
依赖于fete-bird-apigateway
和common
In the fete-bird-product settings.gradle I have included the code below在 fete-bird-product settings.gradle 我已经包含了下面的代码
rootProject.name = "fete-bird-product"
include 'fete-bird-apigateway' , 'common'
and in the build.gradle of project并在项目的 build.gradle
dependencies {
implementation project(':common')
}
Error错误
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching configuration of project:common was found.原因:org.gradle.internal.component.NoMatchingConfigurationSelectionException:没有找到项目的匹配配置:common。
I don't want to create a multi-module build project describe here https://docs.gradle.org/current/userguide/multi_project_builds.html .我不想创建此处描述的多模块构建项目https://docs.gradle.org/current/userguide/multi_project_builds.html 。 Each project should build individually and dependent modules should load while building.每个项目都应该单独构建,依赖模块应该在构建时加载。
How can I achieve this?我怎样才能做到这一点?
Well I found that I had the wrong concept for different module projects.好吧,我发现我对不同的模块项目有错误的概念。
Assuming all modules are part of the same multi-module build then in fete-bird-apigateway.gradle and service\build.gradle you add:假设所有模块都是同一个多模块构建的一部分,然后在 fete-bird-apigateway.gradle 和 service\build.gradle 中添加:
plugins {
id 'java'
id 'maven-publish'
}
dependencies {
implementation project(':common')
}
However if common, fete-bird-apigateway and service are separate projects and don't share the same root build.gradle you have to publish the common module into a shared repository and use it like any regular dependency.但是,如果 common,fete-bird-apigateway 和 service 是单独的项目并且不共享相同的根 build.gradle,则您必须将 common 模块发布到共享存储库中并像任何常规依赖项一样使用它。 Easiest to do with Maven Local repository.最容易使用 Maven 本地存储库。
To publish to the local maven发布到本地 maven
In fete-bird-apigateway.gradle
在fete-bird-apigateway.gradle
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.gradle.sample'
artifactId = 'library'
version = '1.1'
from components.java
}
}
}
Reference - https://docs.gradle.org/current/userguide/declaring_repositories.html https://docs.gradle.org/current/userguide/publishing_maven.html#gsc.tab=0 Reference - https://docs.gradle.org/current/userguide/declaring_repositories.html https://docs.gradle.org/current/userguide/publishing_maven.html#gsc.tab=0
In the dependent project add the dependency as regular在依赖项目中添加依赖作为常规
repositories {
mavenLocal()
}
implementation("fete.bird:fete-bird-apigateway:0.1")
We need to run the task or gradle command for publish.我们需要运行任务或 gradle 命令进行发布。 I am using Intellj so did with below task我正在使用 Intellj,所以完成了以下任务
We can run the gradle command gradle publishToMavenLocal
我们可以运行 gradle 命令gradle publishToMavenLocal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.