29

I recently updated to gradle version 5.0-rc-4, and when running ./gradlew assemble (or any other task) I now get the following message:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.

When I use ./gradlew assemble --warning-mode all I get:

> Configure project :
The DefaultSourceDirectorySet constructor has been deprecated. This is scheduled to be removed in Gradle 6.0. Please use the ObjectFactory service to create instances of SourceDirectorySet instead.

But in the following build.gradle I don't see where I'm using any DefaultSourceDirectorySet, so what is this warning about, and what would I need to change to be compatible with Gradle 6.0?

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.10'
}

dependencies {
    compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}

repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
}

Related

I found create version.txt file in project dir via build.gradle task(gradle 5.0) but I don't have constructs like that so I don't know how it would apply.

I found this deprecation mentioned in the release notes at https://docs.gradle.org/5.0-milestone-1/release-notes.html but they say

In this release of Gradle, the ObjectFactory service, which is part of the public API, now includes a method to create SourceDirectorySet instances. Plugins can now use this method instead of the internal types.

but I don't see how.

I also found the SourceDirectorySet interface at https://docs.gradle.org/current/javadoc/org/gradle/api/file/SourceDirectorySet.html but I don't see how to use it.

Template repository: https://github.com/PHPirates/kotlin-template-project

PHPirate
  • 7,023
  • 7
  • 48
  • 84
  • 1
    I'm guessing that this deprecation message comes from a plugin you are using. In this case, it is probably coming from the kotlin plugin. – mkobit Nov 27 '18 at 15:09
  • @mkobit That would make sense. In that case I trust they'll solve it in time. I'll make sure this question is answered when the warning has disappeared, or when somebody finds out where the warning comes from. – PHPirate Nov 27 '18 at 17:08
  • 3
    This seems relevant – https://discuss.gradle.org/t/the-defaultsourcedirectoryset-constructor-has-been-deprecated/29610 – Thomas David Baker Dec 01 '18 at 23:34
  • @ThomasDavidBaker Yes that seems to be it, thanks for the link! – PHPirate Dec 02 '18 at 11:06
  • 1
    Looks like this has been reported to the Kotlin team: https://youtrack.jetbrains.com/issue/KT-26808 – Javaru Dec 10 '18 at 23:48
  • 1
    @Javaru I see, three months ago... thanks for the link! Will add it to the current answer. – PHPirate Dec 11 '18 at 07:59

1 Answers1

28

Update 2019-01-23 Five minutes ago, kotlin 1.3.20 was released and also updated in the Gradle repository so this issue should be solved by updating the Kotlin Gradle plugin to 1.3.20.

Update 2019-01-11 The target version in Youtrack issue KT-26808 has just been updated to 1.3.20. You can view the latest released version in the Gradle repositories here, but at the moment there are still a lot of open issues for 1.3.20.

Update 2018-12-17 The deprecation warning is fixed in commit https://github.com/JetBrains/kotlin/commit/67e82a54e5ee529116e881953f93a4c8f216e33a, the Youtrack issue is closed. Now waiting for a release to roll out.

As @Javaru pointed out, this has already been reported (in september 2018) at Youtrack issue KT-26808.

Using information from Lance's comment in the link that Thomas David Baker pointed to:

Answer:

If you get this warning while you are not using DefaultSourceDirectorySet directly, this is probably coming from a Gradle plugin you use. You could check this using the --warning-mode all --stacktrace flags for the Gradle build, so like ./gradlew assemble --warning-mode all --stacktrace.

In this particular case it's the Kotlin Gradle Plugin, they use it at DefaultKotlinSourceSet.kt#L140-L155:

private val createDefaultSourceDirectorySet: (name: String?, resolver: FileResolver?) -> SourceDirectorySet = run {
    val klass = DefaultSourceDirectorySet::class.java
    val defaultConstructor = klass.constructorOrNull(String::class.java, FileResolver::class.java)

    if (defaultConstructor != null && defaultConstructor.getAnnotation(java.lang.Deprecated::class.java) == null) {
        // TODO: drop when gradle < 2.12 are obsolete
        { name, resolver -> defaultConstructor.newInstance(name, resolver) }
    } else {
        // (code omitted)
    }
}

We can trust that they will resolve the issue in time, so don't worry about the warning.

PHPirate
  • 7,023
  • 7
  • 48
  • 84
  • 1
    Thanks for keeping the issue up to date. Maybe a link at the top to the issue itself [KT-26808](https://youtrack.jetbrains.net/issue/KT-26808) would be nice too. However it seems that there are still a lot of open tickets: [Open tasks for 1.3.20](https://youtrack.jetbrains.net/issues?q=Target%20versions:%201.3.20%20State:%20Open%20). – rekire Jan 14 '19 at 07:43
  • @rekire You're welcome! Agree, I just added an extra link so it is less hidden. Thanks for the second link, I'm not familiar with the release scheduling but that seems like a lot of issues! – PHPirate Jan 14 '19 at 08:40
  • 2
    I'm not very familiar with the search too, but I tried the search and I have a bug report for 1.3.30 so I was interested for the outstanding work – rekire Jan 15 '19 at 05:05