How to use bom project in application project which import convention plugin?

Description

The sample code contains 3 projects.

  • “platform-bom” is a java-platform type which constraints the dependencies

  • “build-logic” is build logical type which defined a plugin named ‘com.example.my-plugin’. In plugin we define a dependency on platform-bom with maven GAV.

  • “app” is a application type project which use the com.example.my-plugin plugin

Run command

./gradlew run 

Error log

Error log
* What went wrong:
Could not determine the dependencies of task ':app:run'.
> Could not resolve all task dependencies for configuration ':app:runtimeClasspath'.
   > Cannot resolve external dependency com.example:platform-bom:1.0 because no repositories are defined.
     Required by:
         project :app
   > Cannot resolve external dependency jakarta.inject:jakarta.inject-api because no repositories are defined.
     Required by:
         project :app

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Sample Code

Updated test-gradlebuild-deps.zip (165.4 KB)

My question

How can I resolve this problem? Thanks advance.

2024-01-22T16:00:00Z

Add the missing n :slight_smile:

Yes, I have changed ‘implemetation’ to ‘implementation’.
And I changed the POST content. You can find the ERROR LOG part.
But it will get the other problem that I just want to ask.

> Could not determine the dependencies of task ':app:run'.
> > Could not resolve all task dependencies for configuration ':app:runtimeClasspath'.
>    > Cannot resolve external dependency com.example:platform-bom:1.0 because no repositories are defined.
>      Required by:
>          project :app
>    > Cannot resolve external dependency jakarta.inject:jakarta.inject-api because no repositories are defined.
>      Required by:
>          project :app

I will update my attachment.

The ‘com.example:platform-bom’ dependency constraints 'jakarta.inject:jakarta.inject-api:2.0.1' jar file.
But I have to defined the depenpendcy in plugin in build-logic project. This plugin is used in application project app.

dependencies {
  implementation platform("${project.group}:platform-bom:${project.version}") 
}

Is it wrong or not properly?

While you should include build-logic with pluginManagement { ... } as it contributes plugins (and must be done there if you also add some settings plugin), your platform-bom project is nowhere included. And the error about inject-api is as it states. You define a dependency on it, but have no repositories defined. This wouldn’t have changed even if the BOM would be found.

Thanks a lot! I will try it .

1 Like

I have following three changes :

  • settings.gradle
    add the ‘platform-bom’ module.

    rootProject.name="main"  
    includeBuild('build-logic') 
    include 'app', 'platform-bom'
    
  • build-logic\src\main\groovy\com.example.my-plugin.gradle

    dependencies {
    //  implementation platform("${project.group}:platform-bom:${project.version}")
      implementation(platform(project(":platform-bom")))
    }
    
  • platform-bom\build.gradle

      dependencies {
          constraints {
              api('jakarta.inject:jakarta.inject-api:2.0.1')
          }
      }
    

Finally, it’s work.

1 Like