Gradle下编译Modular的问题

鸡窝里的毛 2020-06-25 11:54:36
请问各位大神,这个问题怎么解决?

我创建一个Gradle项目,然后加进了module-info.java


module test {
exports test;
requires com.google.common;
requires fastjson;
}


然后运行:gradlew.bat build报错了。


Working Directory: E:\java\test
Gradle user home: E:\gradle\home
Gradle Distribution: Local installation at E:\gradle\gradle-6.5
Gradle Version: 6.5
Java Home: E:\openjdk\jdk-14
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: build


> Task :compileJava FAILED
E:\java\test\src\main\java\module-info.java:4: 错误: 找不到模块: fastjson
requires fastjson;
^
1 个错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 345ms
1 actionable task: 1 executed


...全文
4835 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
鸡窝里的毛 2020-06-26
  • 打赏
  • 举报
回复
加了,不起作用
builder.gradle


/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.5/userguide/java_library_plugin.html
*/

plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
}
java {
modularity.inferModulePath = true
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
maven{
url 'https://maven.aliyun.com/repository/central'
}
jcenter()
}

dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'

implementation 'com.alibaba:fastjson:1.2.70'

// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
version = '1.2'
tasks.compileJava {
// use the project's version or define one directly
options.javaModuleVersion = provider { project.version }
//options.compilerArgs.addAll( ['--add-modules','fastjson'])
}
qybao 2020-06-26
  • 打赏
  • 举报
回复
gradle项目,不需要配置dependencies吗? 比如 dependencies{ compile 'com.alibaba:fastjson:1.2.70' }
鸡窝里的毛 2020-06-26
  • 打赏
  • 举报
回复

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧