Plugin breaks aar module
See original GitHub issueWhen ktlint plugin is applied to a module that just holds AAR artifact (via allprojects
block), it appears to break that module’s output - build complains about classes from that module missing.
Steps to reproduce:
- Download and assemble KtlintAar.zip
- Note that build will fail
- Go to root
build.gradle
and comment outapply plugin
line forktlint
- Assemble again
- Build will work
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Direct local .aar file dependencies are not supported
The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in...
Read more >Support for bundling sub-modules into a single AAR [62121508]
Please provide a way to create an AAR output that has configured dependencies built in. ... The above mentioned script breaks again with...
Read more >Considerations when creating Android libraries - Medium
Importing a library in our Android app is the same process as importing a .JAR file in a Java app, except that for...
Read more >Upgrading your build from Gradle 4.x to 5.0
Some plugins will break with this new version of Gradle, ... You can remove the --add-modules java.xml.bind option from org.gradle.jvmargs , if set....
Read more >Android Studio 2021.3.1 Closed Issues
"Duplicate content roots detected" with Android Gradle plugin 7.2.0 ... Including navigation graph from different aar module breaks generating ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let’s look at it the other way around: is there any reason for the
ktlint
configuration to be consumable by other projects? The KtLint plugin will resolve it in the same project, but will never need to consume it from another project. IMO the configuration should beisCanBeConsumed = false
andisVisible = false
.Here’s a small reproducer:
Now run
gradle :consumer:dependencies
and/orgradle :consumer:dependencyInsight --configuration compileClasspath --dependency producer
. You can also start poking around: comment out the KtLint plugin, add thejava-base
plugin rather than creating thedefault
configuration manually, add thejava
plugin, add an attribute to thedefault
configuration (any attribute that’s requested byconsumer
, as shown bydependencyInsight
), etc. Depending on the changes, you’ll either see the variant switch fromktlint
todefault
or an error because Gradle cannot determine which variant to use. Notice how the behavior changes depending on the attribute(s) you add to thedefault
configuration.What seems to happen here is that the
default
configuration above is created without attribute, so when the project is consumed from the other project, Gradle has to decide between a variant without attribute and another with one matching/compatible attribute (ktlint
), so it chooses the latter. When you change thedefault
configuration to add one matching attribute, Gradle cannot decide and the build fails. If you add thebundling
attribute and another matching attribute, Gradle will prefer thedefault
configuration over thektlint
one. When you use a previous version of the KtLint plugin, that didn’t declare any attribute on thektlint
configuration, then Gradle chooses thedefault
configuration because it cannot use variant-aware resolution at all. The addition of the attribute on thektlint
configuration that is consumable broke the projects because then it “enabled” variant-aware resolution, andktlint
is a valid variant for the project.You could argue that the
producer
project should declare attributes on itsdefault
configuration, but I’d say thektlint
configuration has no reason to be consumable to begin with.I tested, and adding:
to the
ktlint
configuration fixes the problem. Ideally, this should be added to all the KtLint-related configurations, as there’s no reason that the ruleset, baseline, and reporters be consumable as well. (I explicitly setisCanBeResolved = true
despite that being the default value, for exhaustiveness and explicitness)Excelent description!