gpt4 book ai didi

java - Gradle 为每个子项目调用不同的任务

转载 作者:行者123 更新时间:2023-11-30 00:42:32 28 4
gpt4 key购买 nike

我有以下设置:

项目

  • Spring 启动应用
  • 打包成jar的java类
  • 安卓项目
    • android项目的app模块

我正在尝试设置 gradle 构建,以便我获得可运行的 spring boot jar 应用程序、安装在本地 maven 存储库中的 java jar 库和 android 的 apk 文件。

  • 要获取 apk 文件,我需要运行 assembleDebug 任务
  • 要发布 java 库,我需要运行发布任务
  • 要获得 spring 可执行文件,我需要运行 compileJave 任务

问题是在顶级根 gradel.build 文件上运行什么任务来完成不同的任务?

根目录:

allprojects {
task hello << { task -> println "I'm $task.project.name" }
}
subprojects {
repositories {
mavenCentral()
jcenter()
}
}

Spring Boot 渐变:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

defaultTasks 'clean', 'build'

buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}

jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('io.jsonwebtoken:jjwt:0.7.0')
compile('mysql:mysql-connector-java:6.0.5')

testCompile('org.springframework.boot:spring-boot-starter-test')
}

Java 项目等级:

jar {
baseName = 'commonobjects'
version = "0.0.1-SNAPSHOT"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}

Android 项目等级:

buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}

Android 应用程序等级:

def ANDROID_SUPPORT_DEPENDENCY_VERSION = '25.1.0'
def DAGGER_DEPENDENCY_VERSION = '2.8'
def OK_HTTP_DEPENDENCY_VERSION = '3.5.0'
def RETROFIT_DEPENDENCY_VERSION = '2.1.0'
def RETROFIT_JACKSON_DEPENDENCY_VERSION = '2.1.0'
def BUTTER_KNIFE_DEPENDENCY_VERSION = '8.5.1'
def JAVAX_ANNOTATION_JSR250_API_DEPENDENCY_VERSION = '1.0'
def GREEN_ROBOT_EVENT_BUS_DEPENDENCY_VERSION = '3.0.0'
def RX_JAVA_DEPENDENCY_VERSION = '2.0.5'
def RX_ANDROID_JAVA_DEPENDENCY_VERSION = '2.0.1'

defaultTasks 'clean', 'assembleDebug'

buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
}
}

repositories {
jcenter()
mavenCentral()
}

apply plugin: "com.android.application"
apply plugin: 'idea'


android {
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
applicationId "..."
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

// debug {
// buildConfigField "String", "PARSE_APPLICATION_ID", "\"1\""
// buildConfigField "String", "PARSE_API_KEY", "\"1\""
// }

release {
minifyEnabled true
proguardFiles "android-proguard-android.txt", "proguard-rules.txt"

// buildConfigField "String", "PARSE_APPLICATION_ID", "\"1\""
// buildConfigField "String", "PARSE_API_KEY", "\"1\""
}
}

packagingOptions {
pickFirst 'META-INF/LICENSE'
}
}

dependencies {
// Add jars supplied
compile fileTree(dir: 'libs', include: ['*.jar'])

// Test related
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'

androidTestCompile "com.android.support:support-annotations:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
androidTestCompile "com.android.support.test:runner:0.5"

// Android support libraries
compile "com.android.support:appcompat-v7:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
compile "com.android.support:design:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
compile "com.android.support:support-annotations:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"

// An HTTP & HTTP/2 client for Android and Java applications
compile "com.squareup.okhttp3:okhttp:${OK_HTTP_DEPENDENCY_VERSION}"

// Retrofit: A type-safe HTTP client for Android and Java
compile "com.squareup.retrofit2:retrofit:${RETROFIT_DEPENDENCY_VERSION}"
compile "com.squareup.retrofit2:converter-jackson:${RETROFIT_JACKSON_DEPENDENCY_VERSION}"

// Butterknife: Field and method binding for Android views
compile "com.jakewharton:butterknife:${BUTTER_KNIFE_DEPENDENCY_VERSION}"
annotationProcessor "com.jakewharton:butterknife-compiler:${BUTTER_KNIFE_DEPENDENCY_VERSION}"

// Dagger DI
compile "com.google.dagger:dagger:${DAGGER_DEPENDENCY_VERSION}"
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_DEPENDENCY_VERSION}"
provided "javax.annotation:jsr250-api:${JAVAX_ANNOTATION_JSR250_API_DEPENDENCY_VERSION}"

// Event bus
compile "org.greenrobot:eventbus:${GREEN_ROBOT_EVENT_BUS_DEPENDENCY_VERSION}"

// RxJava a library for composing asynchronous and event-based programs by using observable sequences.
compile "io.reactivex.rxjava2:rxjava:${RX_JAVA_DEPENDENCY_VERSION}"
compile "io.reactivex.rxjava2:rxandroid:${RX_ANDROID_JAVA_DEPENDENCY_VERSION}"
}

最佳答案

您可以简单地创建依赖于三个不同任务的任务。子项目之间也可能存在依赖关系:

task myAllTask {
}

myAllTask.dependsOn assembleDebug, publish, compileJava

对于从子项目运行的任务:

myAllTask.dependsOn ':bootProj:assembleDebug', ':javaProj:publish', ':androidProj:compileJava

关于java - Gradle 为每个子项目调用不同的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42335414/

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