gradle添加模块依赖项

gradle添加模块依赖项

本文介绍了IntelliJ gradle添加模块依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IntelliJ 2016.2。

使用Gradle 2.14.1



我有2个项目,每个项目都有自己的build.gradle文件和单独的目录结构:

  myLib(意思是被其他人破坏并使用)
- build.gradle
- settings.gradle
- src / main / java / ...

sandbox(spring boot web app)
- build.gradle $ b $ - settings.gradle
- src / main / java / ...
- src / main / resources / ...

希望你能得到这张照片。在IntelliJ中,我具有以下模块结构,在同一级别(无子项目):

   -  myLib 
- 沙箱

简单请求...我想使用 myLib 沙箱应用程序中。我希望两个模块都在同一个项目中,以便同时开发这两个模块。



我试着添加一个模块依赖项到 sandbox 在IntelliJ中为 myLib 。没有骰子。我已经尝试添加一个jar引用,没有骰子。



我相信我需要在build.gradle文件中添加一个依赖项,但无法弄清楚。我已经试过编译文件<到myLib.jar的路径>'等。没有骰子。

解决方案本地模块

这是一个模式,后面是大多数Gradle项目,其中有一个库,然后是一个使用该库的示例应用程序
$ b

   - 模块/ 
- build.gradle
- src / main / java
- library /
- build.gradle
- src / main / java
- settings.gradle
- build.gradle

在顶层 settings.gradle 中,您有

  include':library',':module'

然后在 module / build.gradle 中编译包含的项目

 依赖关系{
compile project(':library')
}

基本上,顶层 build.gradle 是子项目和变量的所有常见配置的包装LES。例如,它最常用于Maven URL的 repositories {} 部分。关于这方面的全部细节请见



远程模块



以上是在本地工作的好方法,但假设您想与其他许多开发人员共享您的回购使他们下载额外的源代码。然后你会发布其他库到远程服务器。



如果您的项目在GitHub上为公共,请使用。您还可以在Bintray OSS或Maven Central上设置一个帐户,让您的图书馆可以像其他大多数人一样使用。



如果您的项目在公司内部是私人的,那么您需要一些Maven类型的服务器,无论是通用Web服务器还是Nexus或Artifactory,您可以。

 存储库{
maven {urlhttp://some.maven.site/}
}

然后添加编译执行来源,正常情况

Using IntelliJ 2016.2.
Using Gradle 2.14.1

I have 2 projects, each with their own build.gradle files and separate directory structures:

myLib (meant to be jarred and used by others)
  - build.gradle
  - settings.gradle
  - src/main/java/...

sandbox (spring boot web app)
  - build.gradle
  - settings.gradle
  - src/main/java/...
  - src/main/resources/...

Hopefully, you get the picture. Within IntelliJ, I have the following module structure, at the same level (no subprojects):

- myLib
- sandbox

Simple request ... I want to use myLib within the sandbox app. I want both modules in the same project in order to develop both.

I've tried adding a module dependency to sandbox for myLib within IntelliJ. No dice. I've tried adding a jar reference, no dice.

I believe I need to add a dependency in the build.gradle file but cannot figure out how. I've tried compile files '<path to myLib.jar>', etc. No dice.

解决方案

Local Modules

This is a pattern followed by most Gradle projects where there is a library, then a sample app that uses that library

 - module/
    - build.gradle
    - src/main/java
 - library/
    - build.gradle
    - src/main/java
 - settings.gradle
 - build.gradle

In that top-level settings.gradle you have

include ':library', ':module'

And in the module/build.gradle, you compile that included project

dependencies {
    compile project(':library')
}

Basically, the top-level build.gradle, is a wrapper for all common configs of the sub projects and variables. For example, it's most commonly used for a repositories { } section for Maven urls, for example. Full details on that are at Gradle - Multi-project builds

Remotes Modules

The above is fine for working locally, but let's say you wanted to share your repo with many other developers without making them download extra source code. Then your would publish the other libraries to a remote server.

If your projects are public on GitHub, use a service like jitpack.io. You can also setup an account on Bintray OSS or Maven Central to have your libraries be available like most others.

If your projects are private within your company, you will need some Maven type server, whether that is a generic web server, or Nexus or Artifactory, you can add that with an addition to the repositories block.

repositories {
    maven { url "http://some.maven.site/" }
}

Then add the compile or implementation sources, as normal

这篇关于IntelliJ gradle添加模块依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:02