comahe-de / i18n4k

Internationalization for Kotlin
Apache License 2.0
78 stars 9 forks source link

The i18n4k gradle plugin adds duplicate folders to your SourceSets #28

Closed arpsmack closed 1 year ago

arpsmack commented 1 year ago

See https://github.com/comahe-de/i18n4k/blob/master/i18n4k-gradle-plugin/src/main/kotlin/de/comahe/i18n4k/gradle/plugin/I18n4kPlugin.kt#L159-L163

It grabs a copy of all the existing source folders, adds the new one, and then calls srcDirs which adds all the directories to the source set. This creates a list that looks like:

src/main/resources
src/main/resources
build/generated/resources/i18n4k

Unfortunately it's a bit hard to see that this is happening since a lot of the gradle APIs use Sets and the duplicates often get filtered out, but when the processResources task runs, it definitely ends up trying to copy all your resources twice, leading to build errors (or a ton of warnings if you set duplicatesStrategy = DuplicatesStrategy.WARN).

A simple workaround is either to set duplicatesStrategy and accept that your build will print a bunch of warnings, or to add this to your processResources task (Kotlin DSL syntax):

tasks.processResources {
    doFirst {
        val s = sourceSets.main.get().resources
        s.setSrcDirs(s.srcDirs)
    }
}

s.srcDirs returns a Set of files so it removes the duplicates for you.

comahe-de commented 1 year ago

Hi @arpsmack,

Thank you for the hint. I have fixed it and will prepare a new release in the next days.

comahe-de commented 1 year ago

@arpsmack Could you check if v0.6.0 fixes you problem?

arpsmack commented 1 year ago

@comahe-de Yep, just checked, it's fixed in 0.6.0. Thanks!