我有一个项目,它有多个主类文件, 我可以在我的IDE(intelij)中编译和运行项目,但无法弄清楚如何使用gradle输出工件罐 这是我试过的:
buildscript {
repositories {
jcenter()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
// Add this line
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.2'
}
}
group 'polisotinserter'
version '1.0.0'
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = 1.8
repositories {
jcenter()
maven {
url 'https://artifactory.lyoko.pw:443/libs-release-local'
}
}
dependencies {
compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'
compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
compile group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
compile "org.jsoup:jsoup:1.8.3"
compile group: 'javax.mail', name: 'mail', version: '1.4.7'
compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'org.json', name: 'json', version: '20160810'
compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
}
subprojects {
apply plugin: 'java'
repositories {
jcenter()
maven {
url 'https://artifactory.lyoko.pw:443/libs-release-local'
credentials {
username = "vasilevich"
password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
}
}
}
sourceSets {
main {
java {
srcDir 'src/'
}
}
}
dependencies {
compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
}
}
project(':CGFetcher') {
dependencies {
compile "org.jsoup:jsoup:1.8.3"
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
}
task assembleRelease(type: Jar) {
classifier = 'release'
manifest {
attributes 'Implementation-Title': "CGFetcher",
'Implementation-Version': project.version,
'Main-Class': 'gui.CGGuiMain'
}
baseName = "CGFetcher"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
artifacts {
archives assembleRelease
}
}
使用
运行后gradle build
我在build / libs文件夹中得到一个名为polisotinserter-1.0.0.jar的jar 这是不可取的,而且jar不包含我在project()指令中设置的清单。
经过几次测试后,似乎project()指令根本没有运行,所以我很困惑从哪里开始?我该如何让gradle运行
project(':CGFetcher') {
指令? 谢谢你的关注。
答案 0 :(得分:0)
好的问题是,它不应该出现在项目根目录中,我注意到当我运行gradle build时,它也会生成一个子文件夹CGFetcher 这反过来有自己的构建文件夹和相关的jar。 此外,我注意到它不使用根项目的源,所以我必须这样做:
buildscript {
repositories {
jcenter()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
// Add this line
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.2'
}
}
group 'polisotinserter'
version '1.0.0'
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = 1.8
repositories {
jcenter()
maven {
url 'https://artifactory.lyoko.pw:443/libs-release-local'
}
}
dependencies {
compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'
compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
compile group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
compile "org.jsoup:jsoup:1.8.3"
compile group: 'javax.mail', name: 'mail', version: '1.4.7'
compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'org.json', name: 'json', version: '20160810'
compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
}
sourceSets {
main {
java {
srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
}
resources {
srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
}
}
}
subprojects {
apply plugin: 'java'
repositories {
jcenter()
maven {
url 'https://artifactory.lyoko.pw:443/libs-release-local'
credentials {
username = "vasilevich"
password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
}
}
}
sourceSets {
main {
java {
srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
}
resources {
srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
}
}
}
dependencies {
compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'
compile "org.jsoup:jsoup:1.8.3"
compile group: 'javax.mail', name: 'mail', version: '1.4.7'
compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'org.json', name: 'json', version: '20160810'
compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
}
}
project(':CGFetcher') {
task assembleRelease(type: Jar) {
classifier = 'release'
manifest {
attributes 'Implementation-Title': "CGFetcher",
'Implementation-Version': project.version,
'Main-Class': 'gui.CGGuiMain'
}
baseName = "CGFetcher"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
artifacts {
archives assembleRelease
}
}
通知:
sourceSets {
main {
java {
srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
}
resources {
srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
}
}
}
这告诉项目使用根源代码。 然而,现在出现了一个新问题, 我不知道如何为每个不同的项目创建不同的依赖项似乎gradle强迫我使用所有依赖项,即使它们没有在代码中被非常使用,只是因为包含了类。 编辑: 好吧我也认为那个 simpley,给你所有子项目compileOnly(在较旧的gradle版本中提供) 在实际项目中添加“编译”这里是一个例子:
subprojects {
apply plugin: 'java'
repositories {
jcenter()
maven {
url 'https://artifactory.lyoko.pw:443/libs-release-local'
credentials {
username = "vasilevich"
password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
}
}
}
sourceSets {
main {
java {
srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
}
resources {
srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
}
}
}
dependencies {
compileOnly group: 'com.github.axet', name: 'lookup', version: '0.1.30'
compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
compileOnly group: 'javax.mail', name: 'mail', version: '1.4.7'
compileOnly(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
compileOnly group: 'org.json', name: 'json', version: '20160810'
compileOnly(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
compileOnly(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
compileOnly "org.jsoup:jsoup:1.8.3"
compileOnly(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compileOnly(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
compileOnly group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
}
}
project(':CGFetcher') {
dependencies {
compile "org.jsoup:jsoup:1.8.3"
compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
}
task assembleRelease(type: Jar) {
classifier = 'release'
manifest {
attributes 'Implementation-Title': "CGFetcher",
'Implementation-Version': project.version,
'Main-Class': 'gui.CGGuiMain'
}
baseName = "CGFetcher"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
artifacts {
archives assembleRelease
}
}
这导致没有错误,并且生成的jar与它应该的一样小。