问题是在使用IntelliJ和Gradle向我的第一个Java11模块添加依赖时。

huangapple 未分类评论46阅读模式
英文:

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

问题

我最终正在学习Java 9+模块,并且想要迁移一些旧的1.8项目。

我从简单的开始,创建了一个标准的IntelliJ项目,并创建了以下内容:

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

以下是module-info.java

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

这是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"));
    }
}

以及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'
}

但是在运行gradle的jar任务时,我遇到了以下错误:

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

有人能解释一下为什么吗?

谢谢。

英文:

I am finally learning Java 9+ modules, and I want to migrate some of my old 1.8 projects.

I started simple and created a standard IntelliJ project, and I created this:

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

Here is module-info.java

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

and here is 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

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:

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.

答案1

得分: 0

事实上,根据Gradle的说明,似乎目前还不可能实现:
Gradle文档

我猜我会尝试使用Maven来完成这个。

英文:

In fact, it seems like it is not yet possible, according to Gradle:
Gradle doc

I guess I'll try to do this with Maven instead.

huangapple
  • 本文由 发表于 2020年5月4日 21:31:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61593446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定