如何使用Kotlin DSL使用gradle创建其他Kotlin Sourceet



我想创建一个测试lib源集, src/tlib/kotlin," 之间" main和test。我有这个,但我不确定为什么要使用java源DIR作为Kotlin,我需要根据我的主要来源获取它

sourceSets {
   create("tlib").java.srcDir("src/tlib/kotlin")
}

update

Calebs-MBP:phg-entity calebcushing$ ./gradlew build
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class phg.entity.AbstractEntityBase, unresolved supertypes: org.springframework.data.domain.Persistable
> Task :compileTlibKotlin FAILED

关闭

sourceSets {
    val main by getting
    val tlib by creating {
        java {
            srcDir("src/tlib/kotlin")
            compileClasspath += main.output
            runtimeClasspath += main.output
        }
    }
    val test by getting {
        java {
            compileClasspath += tlib.output
            runtimeClasspath += tlib.output
        }
    }
}
configurations {
    val compile by getting
    val runtime by getting
    val tlibCompile by getting {
        extendsFrom(compile)
    }
    val tlibRuntime by getting {
        extendsFrom(runtime)
    }
    val testCompile by getting {
        extendsFrom(tlibCompile)
    }
    val testRuntime by getting {
        extendsFrom(tlibRuntime)
    }
}
dependencies {
    implementation("${project.group}:constant:[0.1,1.0)")
    api("javax.validation:validation-api")
    api("javax.persistence:javax.persistence-api")
    api("org.springframework.data:spring-data-commons") // has the missing dependency

插件适当地照顾了许多事情,因此加法实际上是关于配置sourceset classpath和接线配置。

这是一个简短的答案,显示classPath配置和一个配置扩展名:

sourceSets {
    val tlib by creating {
        // The kotlin plugin will by default recognise Kotlin sources in src/tlib/kotlin
        compileClasspath += sourceSets["main"].output
        runtimeClasspath += sourceSets["main"].output
    }
}
configurations {
    val tlibImplementation by getting {
        extendsFrom(configurations["implementation"])
    }
}

groovy
有类似的问题如何在Gradle添加新源?


sourceSets {
  val main by getting
  val test by getting
  val tlib by creating {
    java {
      srcDir("src/tlib/kotlin")
      compileClasspath += main.output + test.output
      runtimeClasspath += main.output + test.output
    }
  }
}
configurations {
  val testCompile by getting
  val testRuntime by getting
  val tlibCompile by getting {
    extendsFrom(testCompile)
  }
  val tlibRuntime by getting {
    extendsFrom(testRuntime)
  }
}

相关内容

  • 没有找到相关文章

最新更新