Skip to content
Go back

在gradle项目中使用platform导入其他gradle公共库项目时报错

Edit page

在gradle项目中使用platform导入其他gradle公共库项目时报错

在别的项目中使用platform导入内部公共库时报错, 报错信息如下:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':extractIncludeProto'.
> Could not resolve all files for configuration ':compileProtoPath'.
   > Could not resolve com.fastonetech.library:fastone-bom:1.1.0-SNAPSHOT.
     Required by:
         project :
      > No matching variant of com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT:20221123.055858-93 was found. The consumer was configured to find a runtime of a platform, preferably only the resources files but:
          - Variant 'apiElements' capability com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT declares a component, packaged as a jar:
              - Incompatible because this component declares an API of a library and the consumer needed a runtime of a platform
          - Variant 'runtimeElements' capability com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT declares a runtime of a component, packaged as a jar:
              - Incompatible because this component declares a library and the consumer needed a platform
   > Could not find com.fastonetech.library:filter-spring-boot-starter:.
     Required by:
         project :
   > Could not find com.fastonetech.library:rpc-spring-boot-starter:.
     Required by:
         project :
   > Could not find com.fastonetech.library:security-spring-boot-starter:.
     Required by:
         project :
   > Could not find com.fastonetech.library:prometheus-querying-client:.
     Required by:
         project :

原因

公共库项目应该使用org.gradle.java-platform插件而不是java, 这样才能使用platform导入

解决方案

plugin("org.gradle.java-platform")
configure<JavaPlatformExtension> {
	allowDependencies()
}
when (!isPlatform()) {
	true -> {
		from(components["java"])
		versionMapping {
			usage("java-api") {
				fromResolutionResult()
			}
			usage("java-runtime") {
				fromResolutionResult()
			}
		}
	}

	else -> from(components["javaPlatform"])
}

备注


Edit page
Share this post on:

Previous Post
spring-boot项目中yml配置文件对duration配置在不给定单位的情况下默认为毫秒
Next Post
JavaDelegate里调用Service的方法并且Service方法上有@Transactional注解但DB修改未生效