gradle include语句仅在手动输入时有效

ffscu2ro  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(82)

这里是我的settings.gradle.kts文件的包含部分

rootProject.name = "MyApplication"

// Recursive function to enter all the directories that has a build.gradle.kts file and include them
fun includeModules(set: Set<String>, prefix: String, dir: File): Set<String> {
    val gradlePath = if (dir.name == ".") "" else "$prefix:${dir.name}"
    val intermediateSet = set + if (dir.listFiles()?.firstOrNull { it.name == "build.gradle.kts" } != null &&
        gradlePath != "") {
        println("including $gradlePath")
        setOf(gradlePath)
    } else {
        emptySet()
    }
    return dir.listFiles()?.filter { it.name != "build" && it.isDirectory }
        ?.fold(intermediateSet) { acc: Set<String>, file: File? ->
            acc + includeModules(
                intermediateSet,
                gradlePath,
                file ?: File(".")
            )
        } ?: emptySet()
}

val output = includeModules(emptySet(), "", File(".")).toList()
println("set $output")
val list = mutableListOf<String>()
list.add(":androidApp")
list.add(":shared")
list.add(":desktopApp")
list.add(":client-network:header")
list.add(":client-network:ktorImpl")
list.add(":irc_entities")
list.add(":irc_parser:header")
list.add(":irc_parser:header_test")
list.add(":irc_parser:implementation")
list.add(":TestUtils")
list.add(":client_state:header")
list.add(":client_irc_engine:header")
list.add(":client_irc_engine:implementation")
list.add(":Utility_Functions")
list.add(":bot_prototype:core")
list.add(":bot_prototype:dep_inject")
println("manual $list")
include(output)

字符串
以下是Gradle输出

including :client_irc_engine:implementation
including :client_irc_engine:header
including :irc_parser:implementation
including :irc_parser:header_test
including :irc_parser:header
including :irc_entities
including :Utility_Functions
including :shared
including :client-network:ktorImpl
including :client-network:header
including :desktopApp
including :bot_prototype:core
including :bot_prototype:dep_inject
including :androidApp
including :client_state:header
including :TestUtils
set [:client_irc_engine:implementation, :client_irc_engine:header, :irc_parser:implementation, :irc_parser:header_test, :irc_parser:header, :irc_entities, :Utility_Functions, :shared, :client-network:ktorImpl, :client-network:header, :desktopApp, :bot_prototype:core, :bot_prototype:dep_inject, :androidApp, :client_state:header, :TestUtils]
manual [:androidApp, :shared, :desktopApp, :client-network:header, :client-network:ktorImpl, :irc_entities, :irc_parser:header, :irc_parser:header_test, :irc_parser:implementation, :TestUtils, :client_state:header, :client_irc_engine:header, :client_irc_engine:implementation, :Utility_Functions, :bot_prototype:core, :bot_prototype:dep_inject]

> Configure project :shared
w: The Default Kotlin Hierarchy Template was not applied to 'project ':shared'':
Explicit .dependsOn() edges were configured for the following source sets:
[iosArm64Main, iosMain, iosSimulatorArm64Main, iosX64Main]

Consider removing dependsOn-calls or disabling the default template by adding
    'kotlin.mpp.applyDefaultHierarchyTemplate=false'
to your gradle.properties

Learn more about hierarchy templates: https://kotl.in/hierarchy-template

> Task :commonizeNativeDistribution UP-TO-DATE
> Task :commonize UP-TO-DATE
> Task :prepareKotlinIdeaImport UP-TO-DATE
> Task :androidApp:commonizeCInterop UP-TO-DATE
> Task :androidApp:copyCommonizeCInteropForIde UP-TO-DATE
> Task :androidApp:commonize UP-TO-DATE
> Task :androidApp:prepareKotlinIdeaImport UP-TO-DATE
> Task :desktopApp:commonizeCInterop UP-TO-DATE
> Task :desktopApp:copyCommonizeCInteropForIde UP-TO-DATE
> Task :desktopApp:commonize UP-TO-DATE
> Task :desktopApp:prepareKotlinIdeaImport UP-TO-DATE
> Task :irc_entities:commonizeCInterop UP-TO-DATE
> Task :irc_entities:copyCommonizeCInteropForIde UP-TO-DATE
> Task :irc_entities:commonize UP-TO-DATE
> Task :irc_entities:prepareKotlinIdeaImport UP-TO-DATE
> Task :shared:commonizeCInterop UP-TO-DATE
> Task :shared:copyCommonizeCInteropForIde UP-TO-DATE
> Task :shared:commonize UP-TO-DATE
> Task :shared:transformIosMainCInteropDependenciesMetadataForIde UP-TO-DATE
> Task :shared:prepareKotlinIdeaImport UP-TO-DATE
> Task :TestUtils:commonizeCInterop UP-TO-DATE
> Task :TestUtils:copyCommonizeCInteropForIde UP-TO-DATE
> Task :TestUtils:commonize UP-TO-DATE
> Task :TestUtils:prepareKotlinIdeaImport UP-TO-DATE
> Task :Utility_Functions:commonizeCInterop UP-TO-DATE
> Task :Utility_Functions:copyCommonizeCInteropForIde UP-TO-DATE
> Task :Utility_Functions:commonize UP-TO-DATE
> Task :Utility_Functions:prepareKotlinIdeaImport UP-TO-DATE
> Task :client-network:header:commonizeCInterop UP-TO-DATE
> Task :client-network:header:copyCommonizeCInteropForIde UP-TO-DATE
> Task :client-network:header:commonize UP-TO-DATE
> Task :client-network:header:prepareKotlinIdeaImport UP-TO-DATE
> Task :client-network:ktorImpl:commonizeCInterop UP-TO-DATE
> Task :client-network:ktorImpl:copyCommonizeCInteropForIde UP-TO-DATE
> Task :client-network:ktorImpl:commonize UP-TO-DATE
> Task :client-network:ktorImpl:prepareKotlinIdeaImport UP-TO-DATE
> Task :client_irc_engine:header:commonizeCInterop UP-TO-DATE
> Task :client_irc_engine:header:copyCommonizeCInteropForIde UP-TO-DATE
> Task :client_irc_engine:header:commonize UP-TO-DATE
> Task :client_irc_engine:header:prepareKotlinIdeaImport UP-TO-DATE
> Task :client_irc_engine:implementation:commonizeCInterop UP-TO-DATE
> Task :client_irc_engine:implementation:copyCommonizeCInteropForIde UP-TO-DATE
> Task :client_irc_engine:implementation:commonize UP-TO-DATE
> Task :client_irc_engine:implementation:prepareKotlinIdeaImport UP-TO-DATE
> Task :client_state:header:commonizeCInterop UP-TO-DATE
> Task :client_state:header:copyCommonizeCInteropForIde UP-TO-DATE
> Task :client_state:header:commonize UP-TO-DATE
> Task :client_state:header:prepareKotlinIdeaImport UP-TO-DATE
> Task :irc_parser:header:commonizeCInterop UP-TO-DATE
> Task :irc_parser:header:copyCommonizeCInteropForIde UP-TO-DATE
> Task :irc_parser:header:commonize UP-TO-DATE
> Task :irc_parser:header:prepareKotlinIdeaImport UP-TO-DATE
> Task :irc_parser:header_test:commonizeCInterop UP-TO-DATE
> Task :irc_parser:header_test:copyCommonizeCInteropForIde UP-TO-DATE
> Task :irc_parser:header_test:commonize UP-TO-DATE
> Task :irc_parser:header_test:prepareKotlinIdeaImport UP-TO-DATE
> Task :irc_parser:implementation:commonizeCInterop UP-TO-DATE
> Task :irc_parser:implementation:copyCommonizeCInteropForIde UP-TO-DATE
> Task :irc_parser:implementation:commonize UP-TO-DATE
> Task :irc_parser:implementation:prepareKotlinIdeaImport UP-TO-DATE
> Task :prepareKotlinBuildScriptModel UP-TO-DATE

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.2.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 2s
30 actionable tasks: 30 up-to-date


我创建了很多子项目,并希望他们被自动添加.这里是问题.如果我包括手动键入的列表.一切都很好,但当我使用生成的列表.让我们说,尝试在引擎实现模块中运行一个测试,我得到这个输出

Project directory '/Users/kylemcburnett/IdeaProjects/kmirc/client_irc_engine/implementation' is not part of the build defined by settings file '/Users/kylemcburnett/IdeaProjects/kmirc/settings.gradle.kts'. If this is an unrelated build, it must have its own settings file.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 17ms


两个相同的列表(除了order)。一个是手工输入的,另一个是algo生成的。为什么生成的列表失败了?

0tdrvxhp

0tdrvxhp1#

我发现了这个问题。当我运行测试时,相对文件夹是不同的,gradle再次运行配置阶段,所以要包含的项目列表是空的。这是我修复它的方法。通过指定rootDir开始并从生成的字符串中删除rootDir名称。

fun includeModules(set: Set<String>, prefix: String, dir: File): Set<String> {
    val gradlePath = "$prefix:${dir.name}".removePrefix(":kmirc")
    val intermediateSet = set + if (dir.listFiles()?.firstOrNull { it.name == "build.gradle.kts" } != null &&
        gradlePath != "") {
        println("including $gradlePath")
        setOf(gradlePath)
    } else {
        emptySet()
    }
    return dir.listFiles()?.filter { it.name != "build" && it.isDirectory }
        ?.fold(intermediateSet) { acc: Set<String>, file: File? ->
            acc + includeModules(
                intermediateSet,
                gradlePath,
                file ?: File(".")
            )
        } ?: emptySet()
}

val output = includeModules(emptySet(), "", rootDir).toList().sorted()

字符串

相关问题