1

I have gradle multi-module project configured with kotlin-script. I'd like to add publishing to maven repository and I found maven-publish plugin for it. But it seems to skip the version configured for each project:

MyProject/build.gradle.kts:

subprojects {
    apply {
        plugin("maven-publish")
    }
    configure<PublishingExtension>() {
        publications {
            repositories { ... }
            create<MavenPublication>("myPublication") {
                from(components.getByName("java"))
                logger.lifecycle("test: ${project.group} ${project.name} ${project.version}")
            }
        }

MyProject/subproject1/build.gradle.kts:

version = "1.0.0-SNAPSHOT"

gradle publish output:

test: my.project subproject1 unspecified
artifact file does not exist: '.../MyProject/subproject1/build/libs/subproject1.jar'

File subproject1.jar doesn't exist, but subproject1-1.0.0-SNAPSHOT.jar does. How to make gradle get the correct version of module?

awfun
  • 2,316
  • 4
  • 31
  • 52

1 Answers1

0

I found a similar problem while using the maven-publish plugin:

I was trying to set the repository URL depending on project version as described in the gradle docs here and this answer.

But I found the version always resolved to (as in the question) as the default (un-set) value: unspecified.

So I guess those documentation examples are for a project's build.gradle and not a general gradle script.

Anyway, I believe the problem is due to the timing of the execution of the blocks in the gradle script. The project.version could not be accessed where I wanted it. So I ended up passing a parameter to the gradlew command with the -Pparameter flag.

Gradle has a configuration and then an execution stage.

Refer to documentation:

About your problem, it may be the same as I have described, or perhaps the reason is simpler:

  • Looking at the structure of your gradle file, it does not appear to match the hierarchy specified in the maven-publish documentation. In particular, repositories {} block should be at the same level as publications {}, not inside of it.

Possibly related:

TT--
  • 2,956
  • 1
  • 27
  • 46