Proper structure for multi-module Gradle modules with IntelliJ IDEA

I have a Kotlin project, which consists of three modules:

Core < Service < Web

Structure:

build.gradle
core/
    build.gradle
service/
    build.gradle
web/
    build.gradle

The structure of the root file build.gradle:

buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
subprojects {
    apply plugin: 'kotlin'
    apply plugin: 'jacoco'
    compileKotlin {
        kotlinOptions.jvmTarget = '1.8'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
}

Separate assembly files look like (for core):

dependencies {
    // Kotlin
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    ...
}

And for service(note that the only difference depends on the project):

dependencies {
    compile project (':core')
    // Kotlin
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    ...
}

There are a few optimizations that I would like to do, but I'm still learning Gradle and can't find the right way to reorganize things. I have a problem's:

  • I cannot create serviceeither webindividually, as they complain that they cannot find their dependent subprojects. (For example, through gradle buildthe directory service/).

  • Kotlin stdlib-jre8 , ?

  • /buildscript , mavenCentral()/jcenter()?

, , , /-, , , , , ( 1) Gradle, (2) - IDEA.

+4
1
  • , : gradle :web:build
  • , subprojects, dependencies. , . , compile project(':core') . dependency. , subproject. , , .
  • repository, . buildscript Gradle, . . , , .

Update:

, , ext buildscript, : ext.kotlin_version = '1.1.60', ,

ext {
  kotlin_version = '1.1.60'
  junit_version = '4.12'
}

, , Gradle , , : apply file: "$rootDir/path/to/script.gradle"

№ 3, .

Google maven, android. , , , artefact Gradle ( - jar).

buildscript, (pre-build), mavenCentral(), jcenter() .

+2

Source: https://habr.com/ru/post/1692229/


All Articles