Skip to content

Commit 87f7754

Browse files
fix of sign script generation
1 parent 429f217 commit 87f7754

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/export/GpgSignMavenConfig.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ if (project.hasProperty("signing.gnupg.keyName")) {
2626
def signingTasks = project.getTasks().withType(Sign.class)
2727
mustRunAfter(signingTasks)
2828
}
29+
// Workaround to make test tasks use sign
30+
project.getTasks().withType(Sign.class).configureEach { signTask ->
31+
def withoutSign = (signTask.name.startsWith("sign") ? signTask.name.minus("sign") : signTask.name)
32+
def pubName = withoutSign.endsWith("Publication") ? withoutSign.substring(0, withoutSign.length() - "Publication".length()) : withoutSign
33+
// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets
34+
35+
// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
36+
def debugTestTask = tasks.findByName("linkDebugTest${'$'}pubName")
37+
if (debugTestTask != null) {
38+
signTask.mustRunAfter(debugTestTask)
39+
}
40+
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
41+
def testTask = tasks.findByName("compileTestKotlin${'$'}pubName")
42+
if (testTask != null) {
43+
signTask.mustRunAfter(testTask)
44+
}
45+
}
2946
}
3047
"""
3148
GpgSigning.Enabled ->
@@ -43,5 +60,28 @@ task signAll {
4360
dependsOn(it)
4461
}
4562
}
63+
64+
// Workaround to make android sign operations depend on signing tasks
65+
project.getTasks().withType(AbstractPublishToMaven.class).configureEach {
66+
def signingTasks = project.getTasks().withType(Sign.class)
67+
mustRunAfter(signingTasks)
68+
}
69+
// Workaround to make test tasks use sign
70+
project.getTasks().withType(Sign.class).configureEach { signTask ->
71+
def withoutSign = (signTask.name.startsWith("sign") ? signTask.name.minus("sign") : signTask.name)
72+
def pubName = withoutSign.endsWith("Publication") ? withoutSign.substring(0, withoutSign.length() - "Publication".length()) : withoutSign
73+
// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets
74+
75+
// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
76+
def debugTestTask = tasks.findByName("linkDebugTest${'$'}pubName")
77+
if (debugTestTask != null) {
78+
signTask.mustRunAfter(debugTestTask)
79+
}
80+
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
81+
def testTask = tasks.findByName("compileTestKotlin${'$'}pubName")
82+
if (testTask != null) {
83+
signTask.mustRunAfter(testTask)
84+
}
85+
}
4686
"""
4787
}

0 commit comments

Comments
 (0)