简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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