我有一个项目,它具有多个主类文件,我可以在IDE(intelij)中编译并运行该项目,但是无法弄清楚如何使用gradle输出工件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+')
}
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文件夹中得到一个jar,这个文件夹称为polisotinserter-1.0.0.jar,这是无法预料的,而且jar不包含我在project()指令中设置的清单。
经过几次测试后,似乎project()指令根本没有运行,所以我很困惑从何去何从?我怎样才能让gradle运行
project(':CGFetcher') {
指示?感谢您的关注。
好的问题是,它不应该出现在项目的根目录中,我注意到,当我运行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迫使我使用所有依赖关系,即使它们没有在代码中被强制使用,也仅仅是因为包含了类。编辑:好的,我认为这太简单了,给您的所有子项目compileOnly(在较早的gradle版本中提供),然后在实际项目中添加“ compile”,这是一个示例:
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会像其预期的那样小。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句