-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
[Question] Maven dependency management for monorepo libs #204
Comments
Hi @ToppScorer Thanks for using the plugin and for reporting this. Can you provide the following information,
Your setup seems correct. It possible that the |
Stacktrace
As I'm using the Maven CI Friendly Versions approach, the dependency resolution should work. I think the main problem is that I assume that the library is installed automatically, based on the information from the POM. The library has not been installed manually before. |
Hi, I was not aware of that Maven CI friendly versioning... But I did try to reproduce your setup (one app, one lib, app's See below: npx nx install bootapp --skip-nx-cache --verbose
> NX Running target install for project bootapp and 1 task it depends on:
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> nx run bootlib:install
Executing command: ./mvnw install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.example:demo-lib >------------------------
[INFO] Building bootlib 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ demo-lib ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ demo-lib ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ demo-lib ---
[INFO] skip non existing resourceDirectory /Users/tine/Documents/angular/nx-boot/bootlib/src/test/resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ demo-lib ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:3.0.0:test (default-test) @ demo-lib ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.BootlibApplicationTests
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.038 s - in com.example.demo.BootlibApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ demo-lib ---
[INFO]
[INFO] --- install:3.1.1:install (default-install) @ demo-lib ---
[INFO] Installing /Users/tine/Documents/angular/nx-boot/bootlib/pom.xml to /Users/tine/.m2/repository/com/example/demo-lib/0.0.1-SNAPSHOT/demo-lib-0.0.1-SNAPSHOT.pom
[INFO] Installing /Users/tine/Documents/angular/nx-boot/bootlib/target/demo-lib-0.0.1-SNAPSHOT.jar to /Users/tine/.m2/repository/com/example/demo-lib/0.0.1-SNAPSHOT/demo-lib-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.636 s
[INFO] Finished at: 2023-11-21T09:52:38+01:00
[INFO] ------------------------------------------------------------------------
> nx run bootapp:install
Executing command: ./mvnw install
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building bootapp 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ demo ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ demo ---
[INFO] skip non existing resourceDirectory /Users/tine/Documents/angular/nx-boot/bootapp/src/test/resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:3.0.0:test (default-test) @ demo ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.BootappApplicationTests
09:52:42.480 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.BootappApplicationTests]: BootappApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
09:52:42.589 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.BootappApplication for test class com.example.demo.BootappApplicationTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.5)
2023-11-21T09:52:42.936+01:00 INFO 11994 --- [ main] c.example.demo.BootappApplicationTests : Starting BootappApplicationTests using Java 21.0.1 with PID 11994 (started by tine in /Users/tine/Documents/angular/nx-boot/bootapp)
2023-11-21T09:52:42.937+01:00 INFO 11994 --- [ main] c.example.demo.BootappApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-11-21T09:52:43.871+01:00 INFO 11994 --- [ main] c.example.demo.BootappApplicationTests : Started BootappApplicationTests in 1.138 seconds (process running for 2.092)
WARNING: A Java agent has been loaded dynamically (/Users/tine/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.9/byte-buddy-agent-1.14.9.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.487 s - in com.example.demo.BootappApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ demo ---
[INFO]
[INFO] --- spring-boot:3.1.5:repackage (repackage) @ demo ---
[INFO] Replacing main artifact /Users/tine/Documents/angular/nx-boot/bootapp/target/demo-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /Users/tine/Documents/angular/nx-boot/bootapp/target/demo-0.0.1-SNAPSHOT.jar.original
[INFO]
[INFO] --- install:3.1.1:install (default-install) @ demo ---
[INFO] Installing /Users/tine/Documents/angular/nx-boot/bootapp/pom.xml to /Users/tine/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.pom
[INFO] Installing /Users/tine/Documents/angular/nx-boot/bootapp/target/demo-0.0.1-SNAPSHOT.jar to /Users/tine/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.449 s
[INFO] Finished at: 2023-11-21T09:52:45+01:00
[INFO] ------------------------------------------------------------------------
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target install for project bootapp and 1 task it depends on Question to you: When running |
No, they are not connected, like in you example, so my configuration seems to be wrong. Can you show me your |
Ok that's your issue then! ^^ The setting to connect the
{
"name": "bootapp",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "bootapp/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nxrocks/nx-spring-boot:build",
"options": {
"root": "./bootapp"
},
"dependsOn": [
"^install"
],
"outputs": [
"{workspaceRoot}/bootapp/target"
]
},
"install": {
"executor": "@nxrocks/nx-spring-boot:install",
"options": {
"root": "./bootapp"
},
"dependsOn": [
"^install"
],
"outputs": [
"{workspaceRoot}/bootapp/target"
]
},
"test": {
"executor": "@nxrocks/nx-spring-boot:test",
"options": {
"root": "./bootapp"
},
"outputs": [
"{workspaceRoot}/bootapp/target"
]
},
"clean": {
"executor": "@nxrocks/nx-spring-boot:clean",
"options": {
"root": "./bootapp"
}
},
"run": {
"executor": "@nxrocks/nx-spring-boot:run",
"options": {
"root": "./bootapp"
}
},
"serve": {
"executor": "@nxrocks/nx-spring-boot:serve",
"options": {
"root": "./bootapp"
}
},
"build-image": {
"executor": "@nxrocks/nx-spring-boot:build-image",
"options": {
"root": "./bootapp"
},
"outputs": [
"{workspaceRoot}/bootapp/target"
]
},
"build-info": {
"executor": "@nxrocks/nx-spring-boot:build-info",
"options": {
"root": "./bootapp"
}
}
},
"tags": []
}
|
My |
Can share the two |
I think I found the problem. The
So, it has no
the What's the purpose behind that? |
Humm... That's very odd... there must be something else in your <dependency>
<groupId>com.example</groupId>
<artifactId>example-lib</artifactId>
<version>${project.version}</version>
</dependency> Can you create a minimal reproduction project and push it to github ? |
Yes, here it is https://github.com/ToppScorer/test-monorepo With that setup, running By changing the
it will build the example-lib first. |
I found another problem, which is maybe related. If you don't specify the |
The example repo has a perfectly valid Maven setup. The only real difference I can see compared to your second example is, that the parent definitions are different (where the defined parent also has the The second problem should be easy to fix. For the first one I don't really understand, why it has to have this exact parent. There are different ways, how a Maven Spring-Boot project setup can look like, e. g. importing the |
Hi,
Yes you're right (bad wording from my part), taken individually, each of the project is indeed a valid Maven project
Right now, the plugin rely on I will have another look into this, and try to provide a fix for your use case too Stay tuned |
I'm not sure if it's related, but when I change the |
Hi!
I'm not sure if I use nx-spring-boot in the correct way:
I have a monorepo where I have a Maven library project (under libs) and a Maven application project (under apps). In the POM of the application a dependency to the library project is defined:
When I try to install the application, I would expect, that the library is installed first:
But the Maven build fails because it cannot find the library in the defined Maven repositories. It seems, that the POM is not analyzed.
The text was updated successfully, but these errors were encountered: