如何忽略Gradle依赖关系转换中的项目



我在解析页面上遵循Gradle的Transform依赖项工件中的示例代码。

def artifactType = Attribute.of('artifactType', String)
def minified = Attribute.of('minified', Boolean)
dependencies {
attributesSchema {
attribute(minified)                      
}
artifactTypes.getByName("jar") {
attributes.attribute(minified, false)    
}
}
configurations.all {
afterEvaluate {
if (canBeResolved) {
attributes.attribute(minified, true) 
}
}
}
dependencies {
registerTransform(Minify) {
from.attribute(minified, false).attribute(artifactType, "jar")
to.attribute(minified, true).attribute(artifactType, "jar")
}
}
dependencies {                                 
implementation('com.google.guava:guava:27.1-jre')
implementation(project(':my-sub-project'))
}

当我运行gradlew :my-app:test时,我得到:

FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':my-app:test'.
> Could not resolve all task dependencies for configuration ':my-app:testRuntimeClasspath'.
> Could not resolve project :my-sub-project.
Required by:
project :my-app
> The consumer was configured to find a runtime of a library compatible with Java 17,
packaged as a jar, preferably optimized for standard JVMs, and its dependencies 
declared externally, as well as attribute 'minimized' with value 'true'. 
However we cannot choose between the following variants of project :my-sub-project:
- archives
- checkstyle
- default
- jacocoAgent
- jacocoAnt
- runtimeElements
All of them match the consumer attributes:
...
- Variant 'runtimeElements' capability my_project:my-sub-project:unspecified declares a runtime of a library compatible with Java 17, packaged as a jar, and its dependencies declared externally:
- Unmatched attributes:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about minimized (required 'true')

我如何将我们的内部项目(甚至可能是团队中的库(排除在minimized的要求之外?

我已经设法解决了allprojects:的问题

configurations.all {
// Skip internal projects
allprojects {
attributes.attribute(minimized, true)
}
// Request minimized=true on all resolvable configurations
afterEvaluate {
if (canBeResolved) {
attributes.attribute(minimized, true)
}
}
}

最新更新