简体   繁体   English

使用 IntelliJ 和 gradle 向我的第一个 Java11 模块添加依赖项时出现问题

[英]Problem adding dependencies to my first Java11 module using IntelliJ and gradle

I am finally learning Java 9+ modules, and I want to migrate some of my old 1.8 projects.我终于在学习 Java 9+ 模块,我想迁移一些我的旧 1.8 项目。

I started simple and created a standard IntelliJ project, and I created this:我从简单开始并创建了一个标准的 IntelliJ 项目,然后我创建了这个:

src
|__main
   |__java
      |__myfirst.module
         |__Util.java
      |__module-info.java

Here is module-info.java这是模块信息。java

module myfirst.module {
  requires org.apache.commons.lang3;
  exports myfirst.module;
}

and here is Util.java这里是 Util.java

package myfirst.module;

import org.apache.commons.lang3.math.NumberUtils;

public class Util {
    public static void main(String[] args) {
       System.out.println("Bonjour"+ NumberUtils.isCreatable("Bonjoru"));
    }
}

And the build.gradle和 build.gradle

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.apache.commons:commons-lang3:3.10'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

But when running gradle's jar task, I get the following error:但是在运行 gradle 的 jar 任务时,出现如下错误:

src/main/java/module-info.java:2: error: module not found: org.apache.commons.lang3
    requires org.apache.commons.lang3;

Can someone explain me why?有人可以解释我为什么吗?

Thanks.谢谢。

In fact, it seems like it is not yet possible, according to Gradle: Gradle doc事实上,似乎还不可能,根据 Gradle: Gradle doc

I guess I'll try to do this with Maven instead.我想我会尝试用 Maven 来代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM