forked from Yelp/swagger-gradle-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.gradle.kts
59 lines (54 loc) · 1.98 KB
/
settings.gradle.kts
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
import java.net.URL
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
jcenter()
google()
}
resolutionStrategy {
eachPlugin {
if ("com.android" in requested.id.id) {
useModule("com.android.tools.build:gradle:${requested.version}")
}
}
}
}
include(":plugin")
// Exclude the sample modules from the build if the Codegen plugin is not found in any Maven repository.
if (pluginIsInstalled()) {
include(":samples:junit-tests",
":samples:kotlin-android",
":samples:groovy-android",
":samples:generated-code")
}
fun pluginIsInstalled(): Boolean {
// Building the path to check the in the Maven repository if the plugin is available.
var path = PublishingVersions.PLUGIN_GROUP.replace('.', '/')
path += "/${PublishingVersions.PLUGIN_ARTIFACT}"
path += "/${PublishingVersions.PLUGIN_VERSION}"
path += "/${PublishingVersions.PLUGIN_ARTIFACT}-${PublishingVersions.PLUGIN_VERSION}.jar"
return this
.pluginManagement
.repositories
.filterIsInstance<MavenArtifactRepository>()
.any {
try {
// Gradle portal is exposing a wrong URL:
// https://plugins.gradle.org/m2
// The trailing slash is missing and this is breaking
// URL composition and plugin discovery.
var baseUrlString = it.url.toString()
if (!baseUrlString.endsWith("/")) {
baseUrlString = baseUrlString.plus("/")
}
val baseUrl = URL(baseUrlString)
URL(baseUrl, path).openStream().use { stream ->
return@any stream.read() >= 0
}
} catch (ignored: java.io.IOException) {
return@any false
}
}
}