gpt4 book ai didi

java - 构建主项目时如何自动构建子项目?

转载 作者:行者123 更新时间:2023-12-03 03:55:31 24 4
gpt4 key购买 nike

我正在使用Apache Netbeans IDE,并且正在使用Gradle作为Java应用程序的构建系统。我的项目由一个包含一些GUI代码的主项目和一个子库项目组成。

我希望我的子库项目在构建主项目时自动编译。最简单的方法是什么?

这是我的主要项目的gradle文件:

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'application'

mainClassName = 'ch.minibot32.Launcher'

repositories {
jcenter()
mavenLocal()
mavenCentral()
}

dependencies {
implementation files('../MiniBot32Lib/build/libs/MiniBot32Lib.jar')
compile 'uk.co.electronstudio.sdl2gdx:sdl2gdx:1.0.+'
compile 'com.glazedlists:glazedlists:1.11.0'
compile 'commons-io:commons-io:2.6'
compile 'commons-net:commons-net:3.6'
compile 'org.apache.commons:commons-math3:3.6.1'
compile 'org.apache.commons:commons-lang3:3.9'
compile 'joda-time:joda-time:2.10.5'
testCompile 'junit:junit:4.12'
}

sourceSets {
main {
resources {
srcDir 'res'
}
}
}


jar {
manifest {
attributes 'Main-Class': 'ch.minibot32.Launcher'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}

task createFatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'ch.minibot32.Launcher'
}
baseName = 'MiniBot32-Release'
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}

这是我的子库项目的gradle文件:
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'maven'

repositories {
jcenter()
mavenLocal()
mavenCentral()
}

dependencies {
compile 'commons-io:commons-io:2.6'
compile 'commons-net:commons-net:3.6'
compile 'org.apache.commons:commons-math3:3.6.1'
compile 'org.apache.commons:commons-lang3:3.9'
compile 'joda-time:joda-time:2.10.5'
testCompile 'junit:junit:4.12'
}

jar {
from configurations.compile.collect { zipTree it }
}

更新A

使用来自Eng.Fouad的假定命令时,出现以下错误:
> Project with path ':MiniBot32Lib' could not be found in root project 'MiniBot32'.

我的文件夹层次结构如下所示:
Netbeans_Projects
|_ MiniBot32 <- Main Project
| |_ build
| |_ src
| |_ build.gradle
| |_ settings.gradle
|_ MiniBot32Lib <- Sub Project
|_ build
|_ src
|_ build.gradle
|_ settings.gradle

更新B

另外,我必须在 settings.gradle定义之后将以下内容添加到 rootProject中:
include ':MiniBot32Lib'
project(':MiniBot32Lib').projectDir = new File('../MiniBot32Lib')

谢谢Eng.Fouad!

最佳答案

只需替换:

implementation files('../MiniBot32Lib/build/libs/MiniBot32Lib.jar')


implementation project(":MiniBot32Lib")

这使得子项目成为在构建主项目时构建的依赖项。

关于java - 构建主项目时如何自动构建子项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60526373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com