我想添加一个sourceset sourceSets {
gen {
java.srcDir "src/gen/java"
}
}
。使用groovy这很容易,并已在https://discuss.gradle.org/t/how-to-use-gradle-with-generated-sources/9401/5
java {
sourceSets {
}
}
但是我坚持使用kotlin-dsl添加一个新的。我所拥有的只是:
private let swizzling: (AnyClass, Selector, Selector) -> () = { forClass, originalSelector, swizzledSelector in
let originalMethod = class_getInstanceMethod(forClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector)
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}
extension UIViewController {
static let classInit: Void = {
let originalSelector = #selector(viewDidAppear(_:))
let swizzledSelector = #selector(swizzledViewDidAppear(_:))
swizzling(UIViewController.self, originalSelector, swizzledSelector)
}()
@objc func swizzledViewDidAppear(_ animated: Bool) {
print("Add your logging logic here")
// Call the original viewDidAppear - using the swizzledViewDidAppear signature
swizzledViewDidAppear(animated)
}
}
任何人都可以帮助
答案 0 :(得分:11)
@ s1m0nw1的答案是正确的添加新的源集。 但是要在现有的源集中添加新的源文件夹,可以使用它:
<script type="text/javascript">
function ShowHideDiv() {
var chkYes = document.getElementById("chkYes");
var chkNo = document.getElementById("chkNo");
var creditAmount = document.getElementById("creditAmount");
creditAmount.style.display = chkYes.checked ? "block" : "none";
var day = document.getElementById("day");
day.style.display = chkNo.checked ? "block" : "none";
# condition goes here to clear input value
chkYes.checked ? creditAmount.getElementsByTagName('input')[0].value = "" : day.getElementsByTagName('input')[0].value = ""
</script>
答案 1 :(得分:9)
您应该尝试以下方法:
java.sourceSets.create("src/gen/java")
希望它能满足您的需求!
答案 2 :(得分:3)
我想添加一个名为&#34; test-integration&#34;的源集。和源目录src/test-integration/kotlin
。通过结合两个预先存在的答案,我能够实现这一目标:
java.sourceSets.create("test-integration").java {
srcDir("src/test-integration/kotlin")
}
答案 3 :(得分:3)
在Gradle 4.10.2上为我工作:
sourceSets.create("integrationTest") {
java.srcDir("src/integrationTest/java")
java.srcDir("build/generated/source/apt/integrationTest")
resources.srcDir("src/integrationTest/resources")
}
答案 4 :(得分:0)
在Gradle 4.10.2上为我工作:
sourceSets.getByName("main") {
java.srcDir("src/main/java")
java.srcDir("src/main/kotlin")
}
sourceSets.getByName("test") {
java.srcDir("src/test/java")
java.srcDir("src/test/kotlin")
}
上面的代码也可以在subprojects
块中使用。