我正在尝试将我的MAVEN
构建移动到gradle
因此,我需要解决以下问题:
项目:
- 应用程序(这个应该创建一个胖罐(
插件(应导致单个 jar 文件,但没有胖 jar!
- utils (requires: jarX, jarY, jarZ(
- data (requires: utils, jarX, jarY(
- 控件(需要:data、utils、jarY(
我做的是为每个插件创建一个 jar(但我必须完全定义它的依赖项,这实际上是gradle
的工作所以我所做的是创建 jar 文件,手动将它们复制到reposiory
并声明对这些文件的依赖关系......
所以我期望的是,我只需要告诉应用程序需要控件,因为控件已经包含任何需要的东西(Alsway 包括下面内容的依赖项(
我想我必须定义一个项目(是的,我阅读了 Gradle 的帮助页面,但我无法解决它(
所以现在我在每个插件中都有 settings.gradle,但我读到的是错误的。 我应该只有一个设置.gradle在根目录中。
ROOT: settings.gradle:
include ':application', ':controls', ':data', ':util'
ROOT: build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.glazedlists:glazedlists:1.11.0'
classpath 'org.jooq:jooq:3.12.1'
classpath 'org.controlsfx:controlsfx:8.40.12'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
每个插件都得到了: build.gradle
plugins {
id 'java-library'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
但这也不起作用...
提前致谢
假设您需要执行多项目设置,请执行以下操作:
settings.gradle
rootProject.name = 'mvn2Gradle'
include ':application', ':controls', ':data', ':util'
build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
subprojects {
apply plugin: 'java'
ext {
jarYVersion = '1.x'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation "org.example:jarY:$jarYVersion" // Every subproject gets this dependency
}
}
wrapper { // Run this task once before you start building
gradleVersion = '5.6.3'
distributionType = Wrapper.DistributionType.ALL
}
utils
: build.gradle
plugins {
id 'java-library'
}
ext {
jarXVersion = '1.x'
jarZVersion = '1.x'
}
dependencies {
implementation "org.example:jarX:$jarXVersion"
api "org.example:jarZ:$jarZVersion" // "api" because none of the other projects depends on this jar
}
data
: build.gradle
plugins {
id 'java-library'
}
dependencies {
implementation project(':utils') // Also inherits "jarX"
}
controls
: build.gradle
plugins {
id 'java-library'
}
dependencies {
implementation project(':data') // Also inherits "project:utils"
}
application
: build.gradle
plugins {
id 'application'
}
application {
mainClassName 'my.package.Main'
}
dependencies {
implementation project(':controls')
}