[英]Gradle + Java, multiproject build.gradle
這是我的文件層次結構,“域模塊”目前沒有代碼,基本上是DBController和Domain的包裝。
Domain Module
.gradle
.idea
build
DBController
build
src
main
java
interfaces
IDBController.java
DBController.java
res
some SQL files
test
java
some test files
build.gradle
Domain
.gradle
build
gradle
src
main
java
Server.java
build.gradle
gradlew
gradlew.bat
settings.gradle
gradle
build.gradle
gradlew
gradlew.bat
settings.gradle
這是我在Domain Module / build.gradle中的build.gradle
group 'Group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
targetCompatibility = 1.8
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':Domain')
compile project(':DBController')
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
這是DOmain Module / DBController / build.gradle中的build.gradle
group 'Group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.postgresql:postgresql:9.3-1103-jdbc3'
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile('com.googlecode.json-simple:json-simple:1.1.1')
compile files('libs/json-simple-1.1.1.jar')
compile('org.postgresql:postgresql:9.3-1103-jdbc3')
}
最后,在Domain Module / Domain / build.gradle中建立build.gradle
group 'Group'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
jcenter()
}
sourceCompatibility = 8
targetCompatibility = 8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
dependencies {
compile project(':DBController')
}
我的主要方法在Server.java中,它使用DBController的實例。 如何在Java清單中分配此文件? 我嘗試過簡單
jar {
manifest {
attributes 'Main-Class': 'Domain.src.main.java.Server'
}
但是每當我嘗試執行java -jar-域模塊/ build / libs中生成的jar時,我都會收到一條錯誤消息,告訴我它找不到主文件,並且由於生成網格,它給了我一個錯誤,說有完全沒有提到主類。
我項目的要旨是DBController針對SQL服務器發出查詢,並且Server.java將是spring服務器。 我決定使用gradle進行此操作,這樣我就可以學習,盡管我對gradle有了很多了解,但仍然存在很多不確定性。
我只是想出了什么問題。
jar {
manifest {
attributes 'Main-Class': '-insert main class here-'
}
}
此屬性假定您首先在src / main / java目錄中,所以如果我的文件路徑是
src/main/java/robert/util/Class.java
我只需要說
jar {
manifest {
attributes 'Main-Class': 'robert.util.Class'
}
}
花了這么多時間來解決這種瑣碎的錯誤。 給其他人的提示是不要忽視“介紹入門”等網站。 解決方案一直存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.