0

My project structure is

root
|-- build.gradle
|-- gradle.properties
|-- settings.gradle
|-- module1
    |-- build.gradle.kts
    |-- src
        |-- main
            |-- java
            |-- kotlin
            |-- resources
        |-- test
            |-- kotlin
            |-- resources

I am relatively new to Gradle, and I have the following in my build.gradle

subprojects {
    . . .
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
                versionMapping {
                    usage('java-api') {
                        fromResolutionOf('runtimeClasspath')
                    }
                    usage('java-runtime') {
                        fromResolutionResult()
                    }
                }
                afterEvaluate {
                    pom {
                        name = "pom name"
                        description = "pom description"
                        licenses {
                            license {
                                name = licenseName
                                comments = licenseText
                            }
                        }
                    }
                }   
            }
        }
    }
}

Which mostly does what I want, in particular, licenseName and licenseText are variables I pick up from elsewhere. However, I want to replace "pom name" and "pom description" with context dependent values from elsewhere in this file, or a lower-level file in a subproject. Gradle seems to poo-poo all my efforts to do this... For example, in module1/build.gradle.kts I want to be able to say

val artifactId = project.name
val pomName = "Crypto Common"
val pomDescription = "Libraries common to other Crypto modules."

and in build.gradle replace

name = "pom name"
description = "pom description"

with

name = pomName
description = pomDescription

It's interesting that in build.gradle I can refer to artifactId but not to pomName or pomDescription

Is it possible to do this, and if so, how?

For example, in the project('module1') { ... } closure, or in the build.gradle or build.gradle.kts file one level down in the sub-project/sub-module directory.

Also, is it possible to have a gradle.properties file in sub-modules, or can it only exist in the project root directory?

Eric Kolotyluk
  • 1,958
  • 2
  • 21
  • 30
  • Could you post your directory structure using `tree` or similar. And could you also update your snippet of what you are trying to achieve, specifically what you want `pom.name` and `pom.description` to be/from where. – Cisco May 21 '21 at 01:31
  • Does that help? – Eric Kolotyluk May 21 '21 at 02:39

0 Answers0