2016-05-13 86 views
0

这是我的文件层次结构,'域模块'现在没有代码,基本上是DBController和Domain的包装器。Gradle + Java,多项目build.gradle

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 

这是我在域模块/的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' 
} 

这是在的build.gradle域模块/ DBController /的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') 
} 

最后,在域模块/域/ build.gradle中构建.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' 

} 

但每当我试图执行的罐子-The在域模块/编译/ libs- 我得到一个错误,告诉我它无法找到主文件生成的JAR的Java,而现在的构建阶段,它给了我一个错误,说根本没有提及主类。

我的项目的要点是DBController向SQL服务器发出查询,Server.java将是一个弹簧服务器。我决定使用gradle来做到这一点,所以我会学习,虽然我已经学到了很多关于gradle的知识,但仍然有很多不确定性。

回答

0

我刚才发现什么是错的。

jar { 
    manifest { 
    attributes 'Main-Class': '-insert main class here-' 
    } 
} 

这个属性假设你在src /主/ java的目录开始用的时候,所以如果我的文件路径是

src/main/java/robert/util/Class.java 

我只想不得不说

jar { 
    manifest { 
    attributes 'Main-Class': 'robert.util.Class' 
    } 
} 

花了这么多时间来解决这样一个微不足道的错误。我对其他人的建议是不要忽视'介绍gradle'网站等。解决方案一直存在。