so I’m trying to join several projects into a sing...
# gradle
s
so I’m trying to join several projects into a single multiproject one. This is the kotlin dsl for the parent build.gradle.kts (all subprojects are included via settings.gradle.kts). So the main idea is that we want common versioning for all subprojects: this is my code, but IntelliJ flags basically everything:
Copy code
subprojects {

    plugins {
        java
        idea
        `maven-publish`
        id("pl.allegro.tech.build.axion-release") version "1.9.3"
    }

    group = "uk.co.di.platform"
    version = scmVersion.version


    configure<JavaPluginConvention> {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    repositories {
        mavenCentral()
        mavenLocal()
    } 

    publishing {
        publications {
            create<MavenPublication>("mavenJava") {
                from(components["java"])
            }
        }
    }

    tasks {
        scmVersion {
            versionIncrementer("incrementMinor")
            tag(delegateClosureOf<TagNameSerializationConfig> {
                initialVersion = KotlinClosure2<TagProperties, ScmPosition, String>({ _, _ ->"1.0.0"})
            })
            checks(delegateClosureOf<ChecksConfig> {
                aheadOfRemote = false
                uncommittedChanges = false
            })
        }
    }
}
scmVersion is e.g. flagged as unresolved reverence, but it should have been made accessible by the axion-release plugin.
l
I'm not sure the he
plugins
DSL can work in the
subprojects { }
lambda. You should still be able to share the remaining logic. This article (especially towards the end) should be helpful to you and give your the needed inspiration: https://medium.com/@p.tournaris/reducing-android-gradle-module-configuration-boilerplate-93ee661c80c4
It works for non Android projects too, it's just another Gradle plugin.
s
but I need the plugin do generate the version automatically, it’s not hardcoded 😕 I’ll take a look at that article. Indeed, our’s is not an Android project.
v
The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = “id”) instead.
s
@voben I tried apply(plugin = “id”) but
scmVersion
and
publishing
are still not recognized which means that that not even the
maven-publish
plugin was added correctly.
l
Use
PublishingExtension
s
In what way? https://docs.gradle.org/current/dsl/org.gradle.api.publish.PublishingExtension.html As a replacement to maven-publish? but this setup works for another project (not a root-project). (I’m pretty new to gradle, so ideally I’d stay as close to the initial setup as possible). I added a
buildscript
config, but
scmVersion
is still unresolved (as is publishing). I read the article but that one is mainly concerned with setting the source-version, but my primary problem is the
scmVersion
.
If someone wants to try, this is the complete, latest version:
Copy code
buildscript {
    repositories {
        maven {
            url = uri("<https://plugins.gradle.org/m2/>")
        }
    }
    dependencies {
        classpath("pl.allegro.tech.build:axion-release-plugin:1.9.3")
    }
}

subprojects {

    apply(plugin = "java")
    apply(plugin = "idea")
    apply(plugin = "maven-publish")
    apply(plugin = "pl.allegro.tech.build.axion-release")

    group = "uk.co.whichdigital.di.platform"
    version = scmVersion.version


    configure<JavaPluginConvention> {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    repositories {
        mavenCentral()
        mavenLocal()
    }

    publishing {
        publications {
            create<MavenPublication>("mavenJava") {
                from(components["java"])
            }
        }
    }

    tasks {
        scmVersion {
            versionIncrementer("incrementMinor")
            tag(delegateClosureOf<TagNameSerializationConfig> {
                initialVersion = KotlinClosure2<TagProperties, ScmPosition, String>({ _, _ ->"1.0.0"})
            })
            checks(delegateClosureOf<ChecksConfig> {
                aheadOfRemote = false
                uncommittedChanges = false
            })
        }
    }
}
v
I’m not sure the order in which gradle configures these. But I’m pretty sure
scmVersion
would be available in the app level build.gradle file. Not so sure about the top level build.gradle though
l
Using
configure<PublishingExtension> { }
instead of
publishing { }
👍 1
s
I could live with
version = scmVersion.version
in each subproject, but the whole scmVersion configuration in tasks doesn’t work, and that ’s way to much to replicate over all subprojects.
l
Use
getByName("scmVersion")
. This is Kotlin DSL, not Groovy Gradle with "magic" references
s
according to to docu (https://axion-release-plugin.readthedocs.io/en/latest/configuration/basic_usage/#multi-module-project ) this shouldn’t be to hard:
Copy code
plugins {
    id 'pl.allegro.tech.build.axion-release' version ''
}

scmVersion {
    // ...
}

allprojects {
    project.version = scmVersion.version
}
but what is the Kotlin-DSL version of this? the Groovy class that contains the context of the scmVersion-block is called
VersionConfig
but I guess I have to import it somehow, IntelliJ doesn’t offer autocompeltion.
I’ve got a single-product version where this all works without a problem.
134 Views