SAP-samples / cloud-cap-samples-java

A sample application that demonstrates the features of the Java SDK for the SAP Cloud Application Programming Model.
https://cap.cloud.sap
Apache License 2.0
141 stars 141 forks source link

CdsMojo Build failing #352

Closed finkmanAtSap closed 3 months ago

finkmanAtSap commented 3 months ago

I have cloned the repository with all prerequisites installed but when I run mvn spring-boot:run, I get the following error which does not disappear when I try to run npm install.

[INFO] --- cds:3.1.0:cds (cds.build) @ bookshop ---
[INFO] CdsMojo: Using npx provided by goal install-node: /Users/myUserName/.m2/repository/com/sap/cds/cds-maven-plugin/cache/unpacked/20.15.1/unpacked-20.15.1-darwin-arm64.tar.gz/node-v20.15.1-darwin-arm64/bin/npx
[INFO] CdsMojo: Identified /Users/myUserName/Code/Git/workspace_cap_ams_nodejs/java as reactor base directory.
[INFO] CdsMojo: Using directory containing a .cdsrc.json as working directory: /Users/myUserName/Code/Git/workspace_cap_ams_nodejs/java
[INFO] CdsMojo: Executing [/Users/myUserName/.m2/repository/com/sap/cds/cds-maven-plugin/cache/unpacked/20.15.1/unpacked-20.15.1-darwin-arm64.tar.gz/node-v20.15.1-darwin-arm64/bin/npx, --package, @sap/cds-dk@8.1.0, -c, cds build --for java] in working directory /Users/myUserName/Code/Git/workspace_cap_ams_nodejs/java
[ERROR] CdsMojo: building project [/Users/myUserName/Code/Git/workspace_cap_ams_nodejs/java], clean [true]
cds-dk [8.1.0], cds [8.0.4], compiler [5.0.6], home [/Users/myUserName/Code/Git/workspace_cap_ams_nodejs/node_modules/@sap/cds]

[ERROR] MTX configuration cannot be resolved. Use the 'npm install' command to install up-to-date versions of @sap/cds-mtxs and @sap/cds.
CDS build failed

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for bookshop parent 1.0.0-SNAPSHOT:
[INFO] 
[INFO] bookshop parent .................................... SUCCESS [  0.379 s]
[INFO] bookshop ........................................... FAILURE [  7.411 s]
[INFO] bookshop-integration-tests ......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.098 s
[INFO] Finished at: 2024-08-01T09:06:57+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.sap.cds:cds-maven-plugin:3.1.0:cds (cds.build) on project bookshop: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :bookshop
mofterdinger commented 3 months ago

Hi, it looks like an inconsistency in your local setup. You are using cds-dk 8.1.0 with cds 8.0.4:

cds-dk [8.1.0], cds [8.0.4], compiler [5.0.6], home [/Users/myUserName/Code/Git/workspace_cap_ams_nodejs/node_modules/@sap/cds]

I don't think this is a valid combination. On my machine it looks like this:

cds-dk [8.1.0], cds [8.1.0], compiler [5.1.0], home [/Users/d032842/.npm/_npx/90ef89323fd5c40d/node_modules/@sap/cds-dk/node_modules/@sap/cds]

Please delete the folder node_modules and the file package-lock.json from your local project folder and re-try. I was not able to reproduce with current main branch. Thanks, Markus

finkmanAtSap commented 3 months ago

Thanks for your super fast help! I can confirm that it works fine for me when I clone it into a different folder that is not an NPM workspace.

But unfortunately, I cannot get the sample working inside my NPM workspace where I would like to install/link our cds build/add plugin to develop against a Java project.

I updated my versions but it still does not work:

cds-dk [8.1.0], cds [8.1.0], compiler [5.1.0]

Also,

npm i --workspaces false

says it is adding 1 package but I still cannot see any node_modules folder or package-lock.json inside the local project folder. As there is no package.json in this projec, it feels like there is some internal npm commands going on inside maven that I have no control over that does not like to run inside an npm workspace?

beckermarc commented 3 months ago

I guess your setup broke with our changes we did here: https://github.com/SAP-samples/cloud-cap-samples-java/commit/ad8222acebb47285c30a83b02d0116634b7a2515

We now use an approach where we use npx --package to execute cds build commands. This doesn't require node_modules or package.json in the project.

However I think in a workspace setup you will not want to manage the cds-dk version via the Java build, but via the workspace's package.json. My suggestion would be to remove the property cds.cdsdk-version from the pom.xml. In that case the npx command should pick up the cds-dk from the workspace's node_modules.

You will most likely need to add @sap/cds-mtxs to the workspace's package.json as well (or to a package.json in the bookshop project).

finkmanAtSap commented 3 months ago

Thanks, I can confirm that the app runs fine when I follow your suggestions:

For reference, my workspace's package.json looked like this afterwards:

{
    "workspaces": [
        "./*"
    ],
    "dependencies": {
        "@sap/cds-mtxs": "^2.0.5-2024080608494642-release-SNAPSHOT",
        "@sap/hana-client": "^2.21.28"
    }
}
beckermarc commented 3 months ago

👍

An alternative to adding the dependencies to the workspace's package.json might also be to include the mtx/sidecar from the bookshop project into the workspaces in addition (which already defines these dependencies).