metalava-gradle icon indicating copy to clipboard operation
metalava-gradle copied to clipboard

Test files are included in API files when using Kotlin Multiplatform

Open chrisbanes opened this issue 1 year ago • 4 comments

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.

chrisbanes avatar Jan 08 '24 16:01 chrisbanes

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.

mreichelt avatar Mar 28 '24 08:03 mreichelt

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.

tylerbwong avatar Mar 28 '24 08:03 tylerbwong

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 :)

mreichelt avatar Mar 28 '24 09:03 mreichelt

@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 :)

mreichelt avatar Mar 28 '24 09:03 mreichelt

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.

tylerbwong avatar Jun 13 '24 07:06 tylerbwong