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

cannot serve #20

Closed
draylegend opened this issue Mar 4, 2022 · 13 comments
Closed

cannot serve #20

draylegend opened this issue Mar 4, 2022 · 13 comments

Comments

@draylegend
Copy link

Doesn't serve the api project with the greeting lib.

image

Error

yarn run v1.22.17
$ nx serve api

> nx run api:serve

Executor ran for serve: {}
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------------< de.eon:api >-----------------------------
[INFO] Building api 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.6.3:run (default-cli) > test-compile @ api >>>
[WARNING] The POM for de.eon:greeting:jar:0.0.1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.348 s
[INFO] Finished at: 2022-03-04T11:40:46+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project api: Could not resolve dependencies for project de.eon:api:jar:0.0.1-SNAPSHOT: Could not find artifact de.eon:greeting:jar:0.0.1-SNAPSHOT -> [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/DependencyResolutionException

 ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Running target "api:serve" failed

   Failed tasks:
   
   - api:serve
   
   Hint: run the command with --verbose for more details.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 1

nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.13.1
   OS   : darwin x64
   yarn : 1.22.17
   
   nx : 13.8.4
   @nrwl/angular : 13.8.4
   @nrwl/cli : 13.8.4
   @nrwl/cypress : 13.8.4
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.4
   @nrwl/eslint-plugin-nx : 13.8.4
   @nrwl/express : undefined
   @nrwl/jest : 13.8.4
   @nrwl/js : undefined
   @nrwl/linter : 13.8.4
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : undefined
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.4
   @nrwl/tao : 13.8.4
   @nrwl/web : undefined
   @nrwl/workspace : 13.8.4
   typescript : 4.5.5
   rxjs : 7.4.0
   ---------------------------------------
   Community plugins:
         @angular/animations: 13.2.5
         @angular/common: 13.2.5
         @angular/compiler: 13.2.5
         @angular/core: 13.2.5
         @angular/forms: 13.2.5
         @angular/platform-browser: 13.2.5
         @angular/platform-browser-dynamic: 13.2.5
         @angular/router: 13.2.5
         @angular-devkit/build-angular: 13.2.5
         @angular/cli: 13.2.5
         @angular/compiler-cli: 13.2.5
         @angular/language-service: 13.2.5
         @jnxplus/nx-boot-maven: 1.3.0
@khalilou88
Copy link
Owner

Hi @vladimirdrayling Thank you for raising this. You need to build api before serving it.
The api build will also build deps.
I will check if the serve can depends on the build. Like that we will not need to build.

@draylegend
Copy link
Author

Hi @khalilou88 :)

After clearing node_modules/.cache and running nx build api, it didn't built the api. I got this error:

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] 
[INFO] --------------------------< de.eon:greeting >---------------------------

       Nx is waiting on 1 dependent project tasks before running tasks from api...

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/vladimir.drayling/dev/web/apps/eon/libs/greeting/src/main/resources
[INFO] skip non existing resourceDirectory /Users/vladimir.drayling/dev/web/apps/eon/libs/greeting/src/main/resources

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] Nothing to compile - all classes are up to date

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ greeting ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ greeting ---
[INFO] Changes detected - recompiling the module!

       Nx is waiting on 1 dependent project tasks before running tasks from api...

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] Tests are skipped.

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] Building jar: /Users/vladimir.drayling/dev/web/apps/eon/libs/greeting/target/greeting-0.0.1-SNAPSHOT.jar

       Nx is waiting on 1 dependent project tasks before running tasks from api...
[INFO] Installing /Users/vladimir.drayling/dev/web/apps/eon/libs/greeting/target/greeting-0.0.1-SNAPSHOT.jar to /Users/vladimir.drayling/.m2/repository/de/eon/greeting/0.0.1-SNAPSHOT/greeting-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/vladimir.drayling/dev/web/apps/eon/libs/greeting/pom.xml to /Users/vladimir.drayling/.m2/repository/de/eon/greeting/0.0.1-SNAPSHOT/greeting-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.907 s

       1/1 dependent project tasks succeeded [0 read from cache]

   Hint: you can run the command with --verbose to see the full dependent project outputs

 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————


> nx run api:build

Executor ran for Build: {}
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------------< de.eon:api >-----------------------------
[INFO] Building api 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.675 s
[INFO] Finished at: 2022-03-04T13:46:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project api: Could not resolve dependencies for project de.eon:api:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at de.eon:greeting:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for de.eon:greeting:jar:0.0.1-SNAPSHOT: Could not find artifact de.eon:boot-multi-module:pom:0.0.1-SNAPSHOT -> [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/DependencyResolutionException

 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build for project api and 1 task(s) it depends on (10s)
 
        1/2 failed
        1/2 succeeded [0 read from cache]

@khalilou88
Copy link
Owner

Can you please provide nx.json content?

@draylegend
Copy link
Author

{
  "npmScope": "eon",
  "affected": {
    "defaultBase": "master"
  },
  "cli": {
    "defaultCollection": "@nrwl/angular",
    "packageManager": "yarn"
  },
  "implicitDependencies": {
    "package.json": {
      "dependencies": "*",
      "devDependencies": "*"
    },
    ".eslintrc.json": "*"
  },
  "tasksRunnerOptions": {
    "default": {
      "runner": "@nrwl/workspace/tasks-runners/default",
      "options": {
        "cacheableOperations": ["build", "lint", "test", "e2e"]
      }
    }
  },
  "targetDependencies": {
    "build": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ]
  },
  "generators": {
    "@nrwl/angular:application": {
      "style": "scss",
      "linter": "eslint",
      "unitTestRunner": "jest",
      "e2eTestRunner": "cypress"
    },
    "@nrwl/angular:library": {
      "linter": "eslint",
      "unitTestRunner": "jest"
    },
    "@nrwl/angular:component": {
      "style": "scss"
    }
  },
  "defaultProject": "web-client",
  "plugins": ["@jnxplus/nx-boot-maven"]
}

@khalilou88
Copy link
Owner

the nx.json file has the part about building deps:

  "targetDependencies": {
    "build": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ]
  },

Really, I don't see any problem, try with nx build api --skip-nx-cache
Try to run mvn command directly
You can also share a repo, so we can look together

@draylegend
Copy link
Author

Unfortunately I didn't get it to work :( So here is the repo

@khalilou88
Copy link
Owner

khalilou88 commented Mar 4, 2022

Could you remove the two tests files from api and test again.
Or remove this deps

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
    </dependency>

nx test api didn't work.
the real error is a conflict between deps that you added. maybe you need a database..

@asinkxcoswt
Copy link

asinkxcoswt commented Mar 7, 2022

Hi, could it be related to the problem mentioned in this stackoverflow answer?: https://stackoverflow.com/a/19525334/1078986

I got the same error and can fix by running mvn clean install -N once on the root directory.

What is missing is the artifact for the parent project. After running command above you will find ~/.m2/repository/your/package/{parent_artifact_id} is populated.

@draylegend
Copy link
Author

@asinkxcoswt I'm a newbie regarding java. But your suggestion worked out! Thank you!

Also thank you @khalilou88 for the help! Together you helped to get this to work! :)

Do I need to execute the mvn clean install -N only once? E.g. after creating a workspace with yarn create nx-workspace ..., etc.

@khalilou88 is there a way to integrate the command into init process of your lib?

@asinkxcoswt
Copy link

asinkxcoswt commented Mar 7, 2022

Do I need to execute the mvn clean install -N only once? E.g. after creating a workspace with yarn create nx-workspace ..., etc.

I am not an expert and don't know much about how maven works internally. But as I inspect its behaviors, I found that the parent installed artifact ~/.m2/repository/your/package/{parent_artifact_id}/{version}/{parent_artifact_id}-{version}.pom contains the list of child modules. If you add a new module and don't re-install the parent pom, this file will not include your new module. Despite that, I have tested adding a new module

nx generate @jnxplus/nx-boot-maven:library --name "my-new-lib" --language java --groupId com.mycompany --projectVersion 1.0.0 --projects "my-app"

and then rebuild my-app without installing the parent artifact.

nx build my-app

It turns out my-new-lib and my-app can build properly without problem. So I think it is not neccessary to re-install parent, but I really don't know if it will break in other scenario.

For my project, my team has decided to always re-install the parent project when

  1. After cloning the source code. (e.g. after running npm install).
  2. After adding a new module.
  3. Always re-install in CI pipeline

@khalilou88
Copy link
Owner

khalilou88 commented Mar 8, 2022

@asinkxcoswt @vladimirdrayling Maybe we can add mvn clean install -N before buildings apps.
Somthing like mvn clean install -N && mvn package spring-boot:repackage -DskipTests=true -pl :api
I need to be sure it's not expensive as an operation.

@draylegend
Copy link
Author

Unfortunately I'm not a maven spring boot expert, so I can't really answer your question

@khalilou88
Copy link
Owner

@vladimirdrayling now the build should work without running mvn clean install -N. Check the version 1.5.1

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

3 participants