Gradle Build on pipeline fails during Generation of metadata constants

Hey LEAF,

i just created a gitlab-pipeline for our repository to let the application built automatically.

It seems that the first steps like getting dependencies from nexus and so on are working.
But when at step for the metadata generation is an error:

* Where:
Build file '/builds/mosaic-services/mosaic-services/mosaic-commons/build.gradle' line: 5
* What went wrong:
An exception occurred applying plugin request [id: 'com.leidos.leaf.metadata']
> Failed to apply plugin 'com.leidos.leaf.metadata'.
   > Could not create task ':mosaic-commons:generateMetadataConstants'.
      > Could not create task of type 'GenerateMetadataConstants'.
         > 'org.gradle.api.tasks.JavaExec com.leidos.leaf.gradle.tasks.GenerateMetadataConstants.setMain(java.lang.String)'

The Metadata constants are already generated locally and committed to the branch. Maybe this could be the problem.

Has anyone an idea what i also could look for

Hi Frank,

It looks like the issue is with the version of gradle you are using/the version of Leaf Gradle Plugins, since setMain was recently removed in gradle. Try setting the version of Leaf Gradle Plugins to 3.10.0 and that should fix the issue.

Hi Adam,

the only place where i can find leaf-gradle-plugin with version are config.txt files in the other two projects in this repository. But as stated in the files this is only for documentation purposes.

Is there another place that i can look for the plugin-version

Actually looking at the error more closely that shouldn’t be a problem, if you don’t have any issues building locally it might be something is missing from the pipeline step such as not downloading everything needed, are you using an image to build in the pipeline?

I am using
image: gradle:alpine
on the first line of the pipeline yml.

But in the build stage i dont use any other

On my local environment i use gradle 7.4 to build it.

would it be possible for you to share the build.gradle of that project or at least the plugins portion of it and/or the pipeline file?

# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml

# This is the Gradle build system for JVM applications
# https://gradle.org/
# https://github.com/gradle/gradle

image: gradle:alpine

before_script:
  - GRADLE_USER_HOME="$(pwd)/.gradle"
  - export GRADLE_USER_HOME

build:
  stage: build
  script:
    - echo $NEXUS_USR
    - echo $NEXUS_PSW
    - echo "no one should see pwd"
    - gradle --build-cache assemble
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - build
      - .gradle

test:
  stage: test
  script: gradle check
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: pull
    paths:
      - build
      - .gradle

plugins {
    id 'java-library'
    id 'maven-publish'
    id "com.leidos.leaf.base"
    id "com.leidos.leaf.metadata"
}

// LEAF Configuration

leaf {
    metadata {
        dirs = [
                "src/main/resources/mosaic_commons/device/beanmetadata":
                        "src/main/java/com/leidos/mosaic/commons/generated/metadata"
        ]
        lookupListDirs = [
                "src/main/resources/mosaic_commons/device/lookuplists":
                        "src/main/java/com/leidos/mosaic/commons/generated/lookuplists"
        ]
    }
}

// Dependencies

repositories {
    leafMavenRepo()
    mavenCentral()
}

dependencies {
    api 'com.leidos.leaf:framework-services-rest'

    implementation 'com.auth0:java-jwt:3.18.2'

    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
}

// JUnit Configuration

tasks.named('test') {
    useJUnitPlatform()
}

// Java Configuration and Publishing

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

I think it might have to do with the gradle image being used, I have two ones that might work, for try gradle:8.0.2-jdk17-alpine to see if the alpine image can work if that fails you might have to use gradle:8.0.2-jdk17

Still the same error.
And as i looked into the pipeline run from a few hours ago. It was already on 8.0.2 at the gitlab run. (Only locally i build it with 7.4)

$ gradle --build-cache assemble
Welcome to Gradle 8.0.2!
Here are the highlights of this release:
 - Improvements to the Kotlin DSL
 - Fine-grained parallelism from the first build with configuration cache
 - Configurable Gradle user home cache cleanup
For more details see https://docs.gradle.org/8.0.2/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/builds/mosaic-services/mosaic-services/mosaic-commons/build.gradle' line: 5
* What went wrong:
An exception occurred applying plugin request [id: 'com.leidos.leaf.metadata']
> Failed to apply plugin 'com.leidos.leaf.metadata'.
   > Could not create task ':mosaic-commons:generateMetadataConstants'.
      > Could not create task of type 'GenerateMetadataConstants'.
         > 'org.gradle.api.tasks.JavaExec com.leidos.leaf.gradle.tasks.GenerateMetadataConstants.setMain(java.lang.String)'

Looking at it more my initial guess looks to be right, try upgrading the

id "com.leidos.leaf.base" version "3.9.1" apply false
id "com.leidos.leaf.metadata" version "3.9.1" apply false

to 3.10.0, this could in root level build.gradle, since it’s not specified in the sub-level build.gradle

1 Like

And that worked like a charm. Thank you

3 Likes