Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with options.outputDirLocalRepo #1438

Open
ToppScorer opened this issue Dec 4, 2024 · 16 comments
Open

Problem with options.outputDirLocalRepo #1438

ToppScorer opened this issue Dec 4, 2024 · 16 comments

Comments

@ToppScorer
Copy link

I have the following part in the nx.json:

    "backend-deploy": {
      "cache": true,
      "executor": "@jnxplus/nx-maven:run-task",
      "options": {
        "task": "deploy"
      },
      "dependsOn": [
        "^backend-install"
      ],
      "outputs": [
        "{options.outputDirLocalRepo}",
        "{projectRoot}/.flattened-pom.xml",
        "{projectRoot}/target"
      ]
    },

and in one sub-module this project.json overriding the default task:

    "backend-deploy": {
      "executor": "nx:run-commands",
      "options": {
        "cwd": "{projectRoot}",
        "envFile": "{projectRoot}/.env",
        "commands": [
          "echo Test",
          "docker login",
        ],
        "parallel": false
      },
      "inputs": ["default", "{projectRoot}/.env"]
    },

When running npx nx affected --targets backend-deploy now, I get the following message:

service: > echo 'Test' --outputDirLocalRepo=[localRepo]
service: > docker login  --outputDirLocalRepo=[localRepo]

with the following error:

service: unknown flag: --outputDirLocalRepo

Is it expected, that the outputDirLocalRepo is appended to every command, even if overridden by a different executor?

When I remvove the {options.outputDirLocalRepo} from the outputs in the nx.json, it's working.

@khalilou88
Copy link
Owner

Hi @ToppScorer,

Your use case is not covered.
To make it work i will add two changes:

@khalilou88
Copy link
Owner

@ToppScorer I published version v1.16.0 with the first change. Can you try it ? you need to set outputDirLocalRepo in options object.

@ToppScorer
Copy link
Author

@khalilou88 Unfortunately I'm not able to test it, because I run into some trouble when updating from version 1.8.0 to version 1.16.0. There seems to be a regression, the skipProjectWithoutProjectJson flag does not seem to work anymore. I'm getting Error: Can't find project for file: [redacted]/pom.xml for a project that does not have a project.json. This

check is done too early IMHO. Maybe there should be a new ticket for that.

@khalilou88
Copy link
Owner

@ToppScorer

The error should come from this condition:

          const project = projects.find(
            (element) =>
              joinPathFragments(element.projectRoot, 'pom.xml') === filePath,
          );

Could you please add a console log to see the value of both values ?

@khalilou88
Copy link
Owner

khalilou88 commented Dec 6, 2024

I published version 1.16.1-next.1, with a better condition, maybe it will work for you?
I added some logging
#1442

@ToppScorer
Copy link
Author

ToppScorer commented Dec 9, 2024

@khalilou88 This is the output:

filePath: [redacted: path the to project without project.json]/pom.xml
normalizedFilePath: [redacted: path the to project without project.json]/pom.xml

But paths are the same, relative from the workspace root.

@khalilou88
Copy link
Owner

khalilou88 commented Dec 9, 2024

@ToppScorer I need more information. I was asking if filePath starts with a dot and normalizedFilePath not for example..

joinPathFragments and normalizedFilePath are both from nx lib so they should produce the same result in my opinion, but I think in your case not.

The project we are looking for, exists in nx-maven metadata, using skipProjectWithoutProjectJson or not using it.

I suspect joinPathFragments adding a dot or normalizedFilePath this why we cannot find the project in nx-maven metadata (I am not speaking about nx metadata)

@ToppScorer
Copy link
Author

@khalilou88 Ok, I will try to explain it:

  1. The path for both variable is exactly the same
  2. The project without the project.json is in a folder [workspace-root]/apps/spring-boot/service/infrastructure
  3. The output for both is exactly apps/spring-boot/service/infrastructure/pom.xml
  4. The nx.json contains
  "plugins": [
    {
      "plugin": "@jnxplus/nx-maven",
      "options": {
        "localRepoRelativePath": ".m2/repository",
        "mavenRootDirectory": "libs/spring-boot/root",
        "graphOptions": {
          "skipProjectWithoutProjectJson": true
        }
      }
    }
  ]
  1. The infrastructure project is in a subfolder of another Maven project, but has no relation to it.

@khalilou88
Copy link
Owner

khalilou88 commented Dec 9, 2024

mavenRootDirectory was not designed to work like this. The idea was to put all spring projects in a sub-folder.

We need a reproduction to update the calculation of project root : I do this I think [workspace-root] + mavenRootDirectory + apps/spring-boot/service/infrastructure, but in your case it will not work

@khalilou88
Copy link
Owner

I published version 1.17.0-next.0 to add your case.
PR here: #1444

@ToppScorer
Copy link
Author

ToppScorer commented Dec 10, 2024

@khalilou88 Thanks for the fix, but unfortunately it's still not working. I'm still getting the same error message Error: Can't find project for file: apps/spring-boot/service/infrastructure/pom.xml

@khalilou88
Copy link
Owner

@ToppScorer I created a workspace with your config and can't reproduce your error.

https://github.com/khalilou88/nx-workspace

@ToppScorer
Copy link
Author

@khalilou88 I created a fork an updated the structure a little bit, to reproduce: khalilou88/nx-workspace@main...ToppScorer:nx-workspace:main

In your example the infrastructure project also has a project.json which it should explicitly not have.

@khalilou88
Copy link
Owner

khalilou88 commented Dec 10, 2024

Can you try version 1.9.0, it should work for you. From version 1.10.0 it should break because of this change :https://github.com/khalilou88/jnxplus/pull/1297/files
Based on your reproduction, this project was not present in any modules tag.
I published version 1.16.1, where I change the error to warning and it should work for you now.

@ToppScorer
Copy link
Author

@khalilou88 This is working now for me, thanks for the quick help, appreciate it. One question though:

this project was not present in any modules tag what exactly do you mean by that?

@khalilou88
Copy link
Owner

This: khalilou88/nx-workspace@93464ae

  <modules>
    <module>../parent</module>
    <module>../../../apps/spring-boot/service/infrastructure</module>
  </modules>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants