metalava-gradle
metalava-gradle copied to clipboard
Test files are included in API files when using Kotlin Multiplatform
Example: https://github.com/chrisbanes/haze/blob/main/haze/api/api.txt (notice HazeScreenshotTest
). The HazeScreenshotTest
class is located in commonTest
(here), so seems like something has gone awry in the compile classpath calculation.
I can confirm that also in an Android library, the test
source set seems to be included in the API as well. So it looks like it's a general problem, not just when using Kotlin Multiplatform.
By default the source path is set to src
. If a more granular subdirectory is set by the Gradle plugin such as sourcePaths.setFrom("src/main")
, then anything from the test source set should be excluded.
Thanks for the quick response @tylerbwong! I found out myself that I could use sourcePaths = files(android.sourceSets.named("main").get().java.srcDirs)
to only get that - but I like your workaround more :)
@tylerbwong Do you think it'll be complicated to include only the production source sets of modules by default - not the test source sets? I don't see how any user would want to leak any test sources into the API of a module - but I might be wrong :)
Added some upcoming changes in 54ce413.
Source sets should be detected automatically based on what type of module the plugin is being applied to (excluding test sources by default). The existing sourcePaths
config option has been changed to additionalSourceSets
for consumers to specify their own non-*main source sets.