|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an AS IS BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import java.util.Properties |
| 20 | + |
| 21 | +pluginManagement { |
| 22 | + val parentProperties = java.util.Properties().apply { |
| 23 | + val file = file("../gradle.properties") |
| 24 | + if (file.exists()) { |
| 25 | + file.inputStream().use { load(it) } |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + val mavenCentralTestUrl = parentProperties.getProperty("mavenCentralTestUrl") |
| 30 | + val mavenCentralMirrorUrl = parentProperties.getProperty("mavenCentralMirrorUrl") |
| 31 | + |
| 32 | + val isMavenAccessible = if (!mavenCentralTestUrl.isNullOrBlank()) { |
| 33 | + try { |
| 34 | + val connection = java.net.URL(mavenCentralTestUrl).openConnection() as java.net.HttpURLConnection |
| 35 | + connection.requestMethod = "GET" |
| 36 | + connection.setRequestProperty("User-Agent", "Gradle") |
| 37 | + connection.connectTimeout = 2000 |
| 38 | + connection.readTimeout = 2000 |
| 39 | + connection.useCaches = false |
| 40 | + connection.responseCode == 200 |
| 41 | + } catch (e: Exception) { |
| 42 | + false |
| 43 | + } |
| 44 | + } else { |
| 45 | + true |
| 46 | + } |
| 47 | + System.setProperty("buildSrc.maven.accessible", isMavenAccessible.toString()) |
| 48 | + |
| 49 | + val useFallbackMirror = !isMavenAccessible && !mavenCentralMirrorUrl.isNullOrBlank() |
| 50 | + |
| 51 | + if (isMavenAccessible) { |
| 52 | + logger.lifecycle("Maven Central is accessible. Using default repositories for buildSrc plugins.") |
| 53 | + } else if (useFallbackMirror) { |
| 54 | + logger.lifecycle("Maven Central is not accessible. Falling back to Google Maven Mirror for buildSrc plugins.") |
| 55 | + } else { |
| 56 | + logger.lifecycle("Maven Central is not accessible and no mirror is configured. Using default repositories for buildSrc plugins.") |
| 57 | + } |
| 58 | + |
| 59 | + repositories { |
| 60 | + if (useFallbackMirror) { |
| 61 | + maven { url = uri(mavenCentralMirrorUrl!!) } |
| 62 | + } |
| 63 | + gradlePluginPortal() |
| 64 | + } |
| 65 | +} |
0 commit comments