-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbuild.gradle
146 lines (132 loc) · 4.99 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.regex.Matcher
import java.util.regex.Pattern
plugins {
id 'com.android.application' version libs.versions.agp apply false
id 'com.android.library' version libs.versions.agp apply false
id 'org.jetbrains.kotlin.multiplatform' version libs.versions.kotlin apply false
id 'org.jetbrains.compose' version libs.versions.composeMultiplatform apply false
id 'org.jetbrains.kotlin.android' version libs.versions.kotlin apply false
id "com.vanniktech.maven.publish" version libs.versions.mavenPublish apply false
// Just for Gradle Build, included build will be applied
id("io.github.takahirom.roborazzi") version "1.0.0" apply false
}
allprojects {
// Apply the same Java compatibility for each module
def javaVersion = libs.versions.javaTarget.get()
def toolchainVersion = libs.versions.javaToolchain.get()
def javaTargetVersion = JavaVersion.toVersion(javaVersion)
def jvmTargetVersion = org.jetbrains.kotlin.gradle.dsl.JvmTarget.@Companion.fromTarget(javaVersion)
plugins.withId("java") {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(toolchainVersion))
}
}
}
plugins.withType(com.android.build.gradle.BasePlugin).configureEach {
android {
compileOptions {
sourceCompatibility javaTargetVersion
targetCompatibility javaTargetVersion
}
}
}
tasks.withType(org.gradle.api.tasks.compile.JavaCompile).configureEach {
sourceCompatibility = javaTargetVersion
targetCompatibility = javaTargetVersion
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
jvmTarget.set(jvmTargetVersion)
allWarningsAsErrors = true
}
}
if(project.name.startsWith("roborazzi") &&
project.name != "roborazzi-idea-plugin") {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
freeCompilerArgs.addAll(
"-Xopt-in=com.github.takahirom.roborazzi.InternalRoborazziApi",
"-Xopt-in=com.github.takahirom.roborazzi.ExperimentalRoborazziApi",
)
}
}
}
plugins.withId('com.vanniktech.maven.publish') {
project.group = "io.github.takahirom.roborazzi"
mavenPublishing {
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.S01)
signAllPublications()
}
plugins.withId('maven-publish') {
publishing {
repositories {
maven {
name = "LocalMaven"
url = file("${rootProject.buildDir}/localMaven").toURI().toString()
}
def internalUrl = providers.gradleProperty("internalUrl")
if (internalUrl.isPresent()) {
maven {
name = "internal"
url = internalUrl
credentials {
username = providers.gradleProperty("internalUsername").get()
password = providers.gradleProperty("internalPassword").get()
}
}
}
}
}
}
}
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute(module("io.github.takahirom.roborazzi:roborazzi-compose-preview-scanner-support")).using(project(":roborazzi-compose-preview-scanner-support"))
}
}
}
}
class Topic {
String name
String content
@Override
String toString() {
return "Topic(name: $name, content: ...)"
}
}
def topicsPath = "docs/topics"
def topicsDir = rootProject.file(topicsPath)
def readmeTemplate = rootProject.file("README.template.md")
def readme = rootProject.file("README.md")
// Generate README.md from docs/topics/topic_name.md files by coping
// Insert topics into <topics=name="...">...</topics> by name in README.md
tasks.register("generateReadme") {
doLast {
def readmeContent = readmeTemplate.text
def topicFiles = []
topicsDir.eachFileRecurse { file ->
if (file.name.endsWith(".md")) {
topicFiles.add(file)
}
}
def topics = topicFiles.collect { file ->
def name = file.name.substring(0, file.name.length() - ".md".length())
def content = Matcher.quoteReplacement(file.text)
new Topic(name: name, content: content)
}
def newReadmeContent = readmeContent
println(topics)
topics.forEach { topic ->
def pattern = Pattern.compile("<!-- topic_${topic.name} -->.*?<!-- end -->", Pattern.DOTALL)
def result = pattern.matcher(newReadmeContent).find()
println("topic: $topic pattern: $pattern result: $result")
def generatedComment = "<!-- Generated by $topicsPath/${topic.name}.md. Do not edit this file. -->"
def newTopicContent = "<!-- topic_${topic.name} -->\n\n$generatedComment\n${topic.content}\n<!-- end -->"
newReadmeContent = pattern.matcher(newReadmeContent)
.replaceAll(newTopicContent)
}
readme.write(newReadmeContent)
}
}