Use dependency version from platform outside the dependencies clause

HI,
I’m using the gradle platform plugin; I have a BOM project that declares version constraints, and an App project that gets version recommendations from the BOM project. while this works great for the dependencies clause, I’m not sure if I can get the same recommendations outside of it. for example, I also have the following protobuf clause:

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.11.3"
  }

  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java:1.27.0"
    }
  }
}

is it possible to omit the version numbers and instead take them from the BOM?

thanks!

Hi @asafdav2,

I am not super familiar with the Prorobuf plugin, but it looks like it creates configurations called protobufToolsLocator... for resolving the tools. You can add you platform project to these so that it provides the versions. Then you can define the artifacts without version.

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc"
  }

  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java"
    }
  }
}
configurations.all {
    if (it.name.startsWith('protobufToolsLocator')) {
        it.dependencies.add(project.dependencies.create(platform(project(':my-platform')))
    }
}

Does that work?

so sorry, I somehow missed your reply.

my platform project is not a subproject, so I’m getting this error if I try to use your syntax (assuming my project is called P, my group called X and my artifact called Y):

Project with path ‘X:Y:1.0.+’ could not be found in project ‘:P’.

this is the way I consume my platform right now:

dependencies {
    implementation platform ('X:Y:1.0.+')
}

so I tried to remove the project from the call, like this:

configurations.all {
  if (it.name.startsWith('protobufToolsLocator')) {
    it.dependencies.add(project.dependencies.create(platform('X:Y:1.0.+')))
  }
}

but I’m getting this error message:

Could not find method platform() for arguments [X:Y:1.0.+] on configuration ‘:P:protobufToolsLocator_protoc’ of type org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.

hi @jendrik, sorry for the bump, just was wondering maybe you missed my reply. thanks again