Does anyone have a build.gradle file from a working 3.9 data-service?

I’m trying to upgrade from 3.3 and could really use an example.

Hello! In the gap between 3.3 and 3.9, there are a lot of changes to the dependencies and structure of generated Data Services. If you’re just looking for an example file, then I can provide one in a subsequent post. However, given the number of changes made in between those versions, I would encourage you to install the 3.9 LEAF Service Generators and generate a new Data Service if only to see what a new service looks like including the build.gradle file.

For upgrading your service, their are at least some major tooling changes to deal with including upgrading Gradle from 6.9 to 7.4 and upgrading Java from 11 to 17. For the Gradle upgrade, there are breaking changes to address. For Gradle, the primary change is that the runtime function was removed. For Java, we updated the base images that the generated Java services use out of the box.

For more info about these changes, checkout the posted release notes in the LKB.

While the LEAF Release Notes point you in a direction, they aren’t concrete illustrations of the changes made. That being the case, feel free to post any difficulties you come across and the LEAF team will be sure to try to provide additional details and info about the changes we’ve made along the way.

The service generator fails to build a new data-service

yo @leaf-platform/data-service --use-defaults

   create data-service/config.txt
   create data-service/src/main/java/com/leidos/leaf/data/DataServiceApplication.java
   create data-service/src/integration-test/java/com/leidos/leaf/data/DataServiceApplicationIntegrationTest.java
   create data-service/src/test/java/com/leidos/leaf/data/SampleTest.java
   create data-service/src/main/resources/data_service/lookuplists/TransmissionList.json
   create data-service/src/main/resources/data_service/metadatatemplates/MetadataTemplate.json
   create data-service/src/main/resources/data_service/beanmetadata/Vehicle.json
   create data-service/src/main/resources/log4j2.xml
   create data-service/src/main/resources/openapi-configuration.yaml
   create data-service/values/values-debug.yaml
   create data-service/values/values-prod.yaml
   create data-service/values/values.yaml
   create data-service/.gitignore
   create data-service/build.gradle
   create data-service/README.md
   create data-service/settings.gradle
   create data-service/skaffold.yaml
   create data-service/.devcontainer/devcontainer.json

FAILURE: Build failed with an exception.

* Where:
Build file '/home/docker/leaf/data-service/build.gradle' line: 4

* What went wrong:
Plugin [id: 'com.google.cloud.tools.jib', version: '3.1.4'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:3.1.4')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Leidos Maven Repo(https://nexus.psdo.falc2on.com/repository/maven-public/)
    MavenRepo
    MavenLocal(file:/home/docker/.m2/repository/)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 35s
✖ An error occured while running @leaf-platform/data-service:app#install
Error @leaf-platform/data-service --use-defaults 

Command failed: cd /home/docker/leaf/data-service && gradle wrapper --gradle-version 7.4

FAILURE: Build failed with an exception.

* Where:
Build file '/home/docker/leaf/data-service/build.gradle' line: 4

* What went wrong:
Plugin [id: 'com.google.cloud.tools.jib', version: '3.1.4'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:3.1.4')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Leidos Maven Repo(https://nexus.psdo.falc2on.com/repository/maven-public/)
    MavenRepo
    MavenLocal(file:/home/docker/.m2/repository/)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 35s

I’ve tried a multitude of things to reproduce the error you’re encountering with Gradle failing to find the Jib plugin. I’ve removed my local install of generators and reinstalled the 3.9 official release of them, tried downgrading my Gradle version to 6.9 as well as my Java version to 11, and tried within and outside of a container. In any case, I do not appear to have trouble with Gradle finding Jib.

Of note, all of this testing was completed while on the Leidos VPN.

With that being the case, can you provide more information about your current set up? What version of tooling are you on? You can list out all your LEAF related tooling if you use LEAFctl by running leafctl version -A.

What about a newly generated 3.3 Data Service? Older services should pull the Jib plugin as well, so it would be interesting to know if this is isolated to 3.9 or not.

leafctl version -A
Docker Version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:33 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
Istio Version
1.11.4
Java Version
openjdk 11.0.9.1 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)
LEAF Service Generators Version
@leaf-platform  3.9
Gradle Version

------------------------------------------------------------
Gradle 6.9
------------------------------------------------------------

Build time:   2021-05-07 07:28:53 UTC
Revision:     afe2e24ababc7b0213ccffff44970aa18035fc0e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.9.1 (AdoptOpenJDK 11.0.9.1+1)
OS:           Linux 5.10.76-linuxkit amd64

NodeJS Version
v14.18.1
NPM Version
6.14.15
Yarn Version
1.22.17
Kubectl Version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5", GitCommit:"aea7bbadd2fc0cd689de94a54e5b7b758869d691", GitTreeState:"clean", BuildDate:"2021-09-15T21:10:45Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
Unable to connect to the server: dial tcp 192.168.49.2:8443: connect: no route to host
Helm Version
version.BuildInfo{Version:"v3.7.1", GitCommit:"1d11fcb5d3f3bf00dbe6fe31b8412839a96b3dc4", GitTreeState:"clean", GoVersion:"go1.16.9"}
Skaffold Version
v2.1.0
Minikube Version
minikube version: v1.23.2
commit: 0a0ad764652082477c00d51d2475284b5d39ceed
Kind Version
kind v0.11.1 go1.16.4 linux/amd64
Yeoman Version
4.3.0
Hugo Version
hugo v0.88.1-5BC54738 linux/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
Terraform Version
Terraform v1.0.7
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.3.7. You can update by downloading from https://www.terraform.io/downloads.html

For Java version it says 11, how to I update that to 17?

A recent update to the 3.9 LEAF Knowledge Base has added a page discussing the process for upgrading to Java 17. You can check that out here.

I installed a java 17 jdk and configured it to work with my IDE, and am using gradle wrapper 7.6, but gradle is still configured to use java 11. How do I set the java version for gradle?

In my experience, Gradle uses the JDK you have set for JAVA_HOME in either the ~/.zshrc or ~/.bashrc file. Depending upon how you installed Java, you can set your JAVA_HOME to one of the following:

## Java Home Setup
### Leidos App Store Installs
# export JAVA_HOME="$(/usr/libexec/java_home -v 11)"
# export JAVA_HOME="$(/usr/libexec/java_home -v 17)"
### LEAFctl Install
# export JAVA_HOME="$HOME/<jdk_install_location>/Contents/Home"

When you want to use a particular version of Java, uncomment the version you wish to use and comment out the others. After saving, you need to either run source ~/.zshrc (or source ~/.bashrc) in your terminal tabs or reopen them. At this point, Gradle should be using the version of Java you have set for JAVA_HOME.

Others may have more information and different approaches, but this works for me to go back and forth between Java 11 and Java 17.

I added

export JAVA_HOME="/home/docker/leaf/JDKs/jdk-17.0.6+10"

to both ~/.zshrc and ~.bashrc. But I am still getting the same error. Specifically:

> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.leidos.leaf.gradle:leaf-gradle-plugins:3.9.0.
     Required by:
         project : > com.leidos.leaf.base:com.leidos.leaf.base.gradle.plugin:3.9.0
      > No matching variant of com.leidos.leaf.gradle:leaf-gradle-plugins:3.9.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6' but:
          - Variant 'apiElements' capability com.leidos.leaf.gradle:leaf-gradle-plugins:3.9.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
          - Variant 'runtimeElements' capability com.leidos.leaf.gradle:leaf-gradle-plugins:3.9.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')

Try setting it to export JAVA_HOME="/home/docker/leaf/JDKs/jdk-17.0.6+10/Contents/Home" (i.e. add /Contents/Home to the end) and be sure to reset your terminal/iterm windows afterwards.

Reseting the terminal worked :+1:

but now i’m getting
Value is null
error on line
metadata {

def packageName = 'src/main/resources/otter'
def buildDir = 'src/main/java'

leaf {
    frameworkVersion = "3.9.0"
    platformVersion = "3.9.0"
    metadata {
        dirs = [
            "${packageName}/beanmetadata":
            "${buildDir}/${project.group.replace('.', '/')}/constants"
        ]
        lookupListDirs = [
            "${packageName}/lookuplists":
            "${buildDir}/${project.group.replace('.', '/')}/lookuplists"
        ]
        jar {
            enabled = true
        }
    }
}

have I formatted the section improperly?

Hey there, are you working inside a leaf-dev-env container? If so, what version of the dev container are you using? I’m trying to reproduce your issue.

Also just to double check, have you applied the metadata plugin in your build.gradle?

plugins {
    ...
    id "com.leidos.leaf.base" version "3.9.0"
    id "com.leidos.leaf.metadata" version "3.9.0"
    ...
}

I imagine you’d get that error if you only applied the base plugin, and then tried to specify configuration relevant to the metadata plugin.

Thank you. I imported the metadata library, but forgot to apply it to the subproject. Things are working now :+1:

1 Like

I am now getting an error caused by plugin com.leidos.leaf.dependency-track in the dashboard service.

'com.leidos.leaf.gradle.extensions.dependency.track.LeafDependencyTrackExtension com.leidos.leaf.gradle.extensions.LeafExtension.createDependencyTrackExtension()'

That plugin was deprecated and eventually removed. You could attempt to bring in an older version of it, if your project was actually using it. But it’s likely it was just generated code in the build.gradle that your project doesn’t actually rely on. In which case, it should be safe to remove the plugin and any configuration of that plugin.

when I remove the plugin I get this error on compellation:
cannot find symbol dataService.addDependencyHooks

I think just change that to dataService.addHooks. At this point you’re just getting compile errors from things that have been deprecated in the actual Java code. So that’s a good sign, but there’s probably a little bit of tech debt to resolve. I’d suggest looking over the release notes for each version and checking breaking changes. Use https://docs.leidos-leaf.com/stable/3.9/releases/artifact-type/java-libraries/framework/ for 3.9, and you should be able to change the version in the URL to see others. Specifically looking for the Breaking Changes sections on each page. But also feel free to ping me for anything else that breaks to speed things up.

Started getting this error after clearing my gradle cache:

> Could not resolve all files for configuration ':classpath'.
   > Could not find any version that matches org.apache.logging.log4j:log4j-core:{strictly [2.17, 3[; prefer 2.19.0}.
     Versions that do not match: 3.0.0-SNAPSHOT
     Searched in the following locations:
       - file:/home/docker/.m2/repository/org/apache/logging/log4j/log4j-core/
       - https://nexus.psdo.falc2on.com/repository/maven-public/org/apache/logging/log4j/log4j-core/maven-metadata.xml
       - https://nexus.psdo.falc2on.com/repository/maven-public/org/apache/logging/log4j/log4j-core/2.29.1-SNAPSHOT/maven-metadata.xml
       - https://nexus.psdo.falc2on.com/repository/maven-public/org/apache/logging/log4j/log4j-core/2.29.1-SNAPSHOT/log4j-core-2.29.1-SNAPSHOT.pom
     Required by:
         project : > com.leidos.leaf.base:com.leidos.leaf.base.gradle.plugin:3.9.0 > com.leidos.leaf.gradle:leaf-gradle-plugins:3.9.0 > com.leidos.leaf:framework-services-tools:3.9.0-rc.1

where am I supposed to be pulling this from?

Do you have any mentions of log4j in your build.gradle pointing to a specific log4j version? It’s possible you’re trying to pull in a version that LEAF’s constraint won’t allow because of the log4shell vulnerability.

If it’s specified in a block like this in your build.gradle,

ext {
    versions = [
        prometheus: "0.8.0",
        jettyMetrics: "4.1.0",
        log4j2: "2.19.0",
        junit: "5.7.1"
    ]

I’d suggest changing the version to 2.19.0 or higher.