ionic-team/trapeze

java not found error even when not using gradle command

EranClientside opened this issue · 5 comments

I'm using trapeze in my Bitbucket Pipeline and Appflow. It worked as expected for a few months but after upgrading from 6.0.10 to 7.0.8 it failed most of the time in the Pipeline because of the following error:

Fatal error: Error running command
Error: java not found on path and JAVA_HOME not set. Please set JAVA_HOME to the root of your Java installation.
Gradle parse functionality depends on a local Java install for accurate Gradle file modification.
    at GradleFile.parse (/opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/project/dist/android/gradle-file.js:196:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async GradleFile.replaceProperties (/opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/project/dist/android/gradle-file.js:53:9)
    at async executeOperations (/opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/configure/dist/tasks/run.js:52:10)
    at async runCommand (/opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/configure/dist/tasks/run.js:31:9)
    at async /opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/configure/dist/index.js:58:13
    at async Command.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/@trapezedev/configure/dist/util/cli.js:31:13)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'm using node:14 image and didn't know I must have Java before the upgrade.
I tested every single release since 6.0.10 and this issue started in the version 6.0.12.

You'll need Java to run Android tasks, do you have it installed?

Is that now required for all of the Android commands?
As I mentioned above, our trapeze configuration worked without Java until v6.0.10.

Yes, it has been since the beginning pretty much. It's possible something else was masking it. Java is required for many of the Gradle operations for Android and many of the Android operations ultimately need to make Gradle modifications

Well, the following ymls worked without it 🤷‍♂️

vars:
  npm_package_version:

platforms:
  ios:
    version: $npm_package_version
  android:
    versionName: $npm_package_version
    incrementVersionCode: true

project:
  json:
    - file: src-capacitor/package.json
      set:
        version: $npm_package_version
vars:
  npm_package_version:
    default: 1

  CI_BUILD_NUMBER:
    default: 1

platforms:
  android:
    versionName: $npm_package_version
    versionCode: $CI_BUILD_NUMBER
    copy:
      - src: ../../trapeze/firebase/google-services-testing.json
        dest: app/google-services.json
      - src: ../../trapeze/icons/android
        dest: ../android
    xml:
      - resFile: values/strings.xml
        target: resources/string[@name="onesignal_notification_accent_color"]
        replace: |
          <string name="onesignal_notification_accent_color">FFFFB738</string>
  ios:
    version: $npm_package_version
    buildNumber: $CI_BUILD_NUMBER
    copy:
      - src: ../../../trapeze/firebase/GoogleService-Info-testing.plist
        dest: App/GoogleService-Info.plist
      - src: ../../../trapeze/icons/ios
        dest: ../../ios

There have been a lot of changes and some of the Android operations may have moved to using the Gradle parser (which requires Java) to be more accurate. I don't recommend using older versions of Trapeze as a lot has changed. Make sure any build runners you have have Java installed.