繁体   English   中英

如何使 android 和 spring 作为模块一起存在于一个项目中?

[英]How to make android and spring to exists together as modules in one project?

:) 最后几天我做了一些 kotlin 个项目只是为了好玩。 每个项目都在 kotlin 中创建为 web 应用程序(spring)和移动(android)。 我开始想知道是否有可能配置多模块项目,其中 spring 和 android 可以作为模块存储在一起? 我读了一些关于多模块项目的文章,但通常只有 web 个应用程序。 我尝试自己做一些事情,但没有任何效果;p 这是我的 gradle 文件:

setting.gradle.kts(弹簧网)

rootProject.name = "web"

build.gradle.kts(弹簧网)

plugins {
    id("org.springframework.boot") version "3.0.1"
    id("io.spring.dependency-management") version "1.1.0"
    kotlin("jvm") version "1.7.22"
    kotlin("plugin.spring") version "1.7.22"
    kotlin("plugin.jpa") version "1.7.22"
}

group = "pl.mattiahit.myrestaurant.web"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-validation")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.modelmapper:modelmapper:3.1.1")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

build.gradle.kts (安卓)

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "pl.mattiahit.myrestaurant.mobile"
    compileSdk = 32

    defaultConfig {
        applicationId = "pl.mattiahit.myrestaurant.mobile"
        minSdk = 24
        targetSdk = 32
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {

    implementation("com.android.support:appcompat-v7:28.0.0")
    implementation("com.android.support.constraint:constraint-layout:2.0.4")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("com.android.support.test:runner:1.0.2")
    androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
}

settings.gradle.kts(父级)

rootProject.name = "MyRestaurant"

include("web")
include("mobile")

build.gradle.kts(父)

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
    }
}

我收到错误

A problem occurred configuring root project 'MyRestaurant'.
> Could not resolve all files for configuration ':classpath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0 because no repositories are defined.
     Required by:
         project :

我没有此类项目的经验......任何人都可以帮助我吗? 有没有关于多模块项目等的好文章?

正如错误所暗示的那样,您缺少顶级(“父级”) build.gradle.kts中的repositories块:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM