Skip to content

Commit 552c8ac

Browse files
matikepaMateusz (Mati) Kepa
andauthored
Update Gradle cache with the configurable plugin support (#114)
* feat(gradle): add request metrics for build cache handler * Implement fallback handling for Gradle plugin requests and update tests * refactor(gradle): simplify response handling and remove unused metrics assertions * Add tests for Gradle plugin metadata fallback and refactor metadata handling --------- Co-authored-by: Mateusz (Mati) Kepa <m.kepa@sportradar.com>
1 parent 76f41cf commit 552c8ac

12 files changed

Lines changed: 476 additions & 26 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ Add to your `~/.m2/settings.xml`:
210210
</settings>
211211
```
212212

213+
The `/maven/` endpoint uses Maven Central as primary upstream and falls back to the Gradle Plugin Portal for Gradle plugin marker metadata and related artifacts when the primary upstream returns not found.
214+
215+
For Gradle plugin resolution via the same proxy endpoint:
216+
217+
```kotlin
218+
pluginManagement {
219+
repositories {
220+
maven(url = "http://localhost:8080/maven/")
221+
}
222+
}
223+
```
224+
213225
### Gradle HTTP Build Cache
214226

215227
Configure in `settings.gradle(.kts)`:
@@ -386,6 +398,7 @@ sudo dnf update
386398
## Configuration
387399

388400
The proxy can be configured via:
401+
389402
1. Command line flags (highest priority)
390403
2. Environment variables
391404
3. Configuration file (YAML or JSON)
@@ -977,6 +990,7 @@ The proxy will recreate the database on next start.
977990
## Building from Source
978991

979992
Requirements:
993+
980994
- Go 1.25 or later
981995

982996
```bash

cmd/proxy/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
// PROXY_DATABASE_URL - PostgreSQL connection URL
7373
// PROXY_LOG_LEVEL - Log level
7474
// PROXY_LOG_FORMAT - Log format
75+
// PROXY_UPSTREAM_MAVEN - Maven repository upstream URL
76+
// PROXY_UPSTREAM_GRADLE_PLUGIN_PORTAL - Gradle Plugin Portal upstream URL
7577
// PROXY_GRADLE_BUILD_CACHE_READ_ONLY - Disable Gradle PUT uploads
7678
// PROXY_GRADLE_BUILD_CACHE_MAX_UPLOAD_SIZE - Max Gradle PUT request body size
7779
// PROXY_GRADLE_BUILD_CACHE_MAX_AGE - Gradle cache max age eviction
@@ -199,6 +201,8 @@ func runServe() {
199201
fmt.Fprintf(os.Stderr, " PROXY_DATABASE_URL PostgreSQL connection URL\n")
200202
fmt.Fprintf(os.Stderr, " PROXY_LOG_LEVEL Log level\n")
201203
fmt.Fprintf(os.Stderr, " PROXY_LOG_FORMAT Log format\n")
204+
fmt.Fprintf(os.Stderr, " PROXY_UPSTREAM_MAVEN Maven repository upstream URL\n")
205+
fmt.Fprintf(os.Stderr, " PROXY_UPSTREAM_GRADLE_PLUGIN_PORTAL Gradle Plugin Portal upstream URL\n")
202206
fmt.Fprintf(os.Stderr, " PROXY_GRADLE_BUILD_CACHE_READ_ONLY Disable Gradle PUT uploads\n")
203207
fmt.Fprintf(os.Stderr, " PROXY_GRADLE_BUILD_CACHE_MAX_UPLOAD_SIZE Max Gradle PUT request body size\n")
204208
fmt.Fprintf(os.Stderr, " PROXY_GRADLE_BUILD_CACHE_MAX_AGE Gradle cache max age eviction\n")

config.example.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ upstream:
7171
# npm registry URL
7272
npm: "https://registry.npmjs.org"
7373

74+
# Maven repository URL (used by /maven endpoint)
75+
maven: "https://repo1.maven.org/maven2"
76+
77+
# Gradle Plugin Portal Maven URL (fallback for plugin marker artifacts)
78+
gradle_plugin_portal: "https://plugins.gradle.org/m2"
79+
7480
# Cargo sparse index URL
7581
cargo: "https://index.crates.io"
7682

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Override default upstream registry URLs:
114114
```yaml
115115
upstream:
116116
npm: "https://registry.npmjs.org"
117+
maven: "https://repo1.maven.org/maven2"
118+
gradle_plugin_portal: "https://plugins.gradle.org/m2"
117119
cargo: "https://index.crates.io"
118120
cargo_download: "https://static.crates.io/crates"
119121
```

internal/config/config.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ type UpstreamConfig struct {
221221
// Default: https://registry.npmjs.org
222222
NPM string `json:"npm" yaml:"npm"`
223223

224+
// Maven is the upstream Maven repository URL.
225+
// Default: https://repo1.maven.org/maven2
226+
Maven string `json:"maven" yaml:"maven"`
227+
228+
// GradlePluginPortal is the upstream Gradle Plugin Portal Maven URL.
229+
// Used to resolve Gradle plugin marker artifacts.
230+
// Default: https://plugins.gradle.org/m2
231+
GradlePluginPortal string `json:"gradle_plugin_portal" yaml:"gradle_plugin_portal"`
232+
224233
// Cargo is the upstream cargo index URL.
225234
// Default: https://index.crates.io
226235
Cargo string `json:"cargo" yaml:"cargo"`
@@ -298,9 +307,11 @@ func Default() *Config {
298307
Format: "text",
299308
},
300309
Upstream: UpstreamConfig{
301-
NPM: "https://registry.npmjs.org",
302-
Cargo: "https://index.crates.io",
303-
CargoDownload: "https://static.crates.io/crates",
310+
NPM: "https://registry.npmjs.org",
311+
Maven: "https://repo1.maven.org/maven2",
312+
GradlePluginPortal: "https://plugins.gradle.org/m2",
313+
Cargo: "https://index.crates.io",
314+
CargoDownload: "https://static.crates.io/crates",
304315
},
305316
Gradle: GradleConfig{
306317
BuildCache: GradleBuildCacheConfig{
@@ -395,6 +406,12 @@ func (c *Config) LoadFromEnv() {
395406
if v := os.Getenv("PROXY_LOG_FORMAT"); v != "" {
396407
c.Log.Format = v
397408
}
409+
if v := os.Getenv("PROXY_UPSTREAM_MAVEN"); v != "" {
410+
c.Upstream.Maven = v
411+
}
412+
if v := os.Getenv("PROXY_UPSTREAM_GRADLE_PLUGIN_PORTAL"); v != "" {
413+
c.Upstream.GradlePluginPortal = v
414+
}
398415
if v := os.Getenv("PROXY_COOLDOWN_DEFAULT"); v != "" {
399416
c.Cooldown.Default = v
400417
}

internal/config/config_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ func TestDefault(t *testing.T) {
3131
if cfg.Gradle.BuildCache.MaxAge != "168h" {
3232
t.Errorf("Gradle.BuildCache.MaxAge = %q, want %q", cfg.Gradle.BuildCache.MaxAge, "168h")
3333
}
34+
if cfg.Upstream.Maven != "https://repo1.maven.org/maven2" {
35+
t.Errorf("Upstream.Maven = %q, want %q", cfg.Upstream.Maven, "https://repo1.maven.org/maven2")
36+
}
37+
if cfg.Upstream.GradlePluginPortal != "https://plugins.gradle.org/m2" {
38+
t.Errorf("Upstream.GradlePluginPortal = %q, want %q", cfg.Upstream.GradlePluginPortal, "https://plugins.gradle.org/m2")
39+
}
3440
}
3541

3642
func TestValidate(t *testing.T) {
@@ -264,6 +270,8 @@ func TestLoadFromEnv(t *testing.T) {
264270
t.Setenv("PROXY_BASE_URL", "https://env.example.com")
265271
t.Setenv("PROXY_STORAGE_PATH", "/env/cache")
266272
t.Setenv("PROXY_LOG_LEVEL", testLevelDebug)
273+
t.Setenv("PROXY_UPSTREAM_MAVEN", "https://maven.example.com/repository/maven-public")
274+
t.Setenv("PROXY_UPSTREAM_GRADLE_PLUGIN_PORTAL", "https://plugins.example.com/m2")
267275
t.Setenv("PROXY_GRADLE_BUILD_CACHE_READ_ONLY", "true")
268276
t.Setenv("PROXY_GRADLE_BUILD_CACHE_MAX_UPLOAD_SIZE", "32MB")
269277
t.Setenv("PROXY_GRADLE_BUILD_CACHE_MAX_AGE", "12h")
@@ -284,6 +292,12 @@ func TestLoadFromEnv(t *testing.T) {
284292
if cfg.Log.Level != testLevelDebug {
285293
t.Errorf("Log.Level = %q, want %q", cfg.Log.Level, testLevelDebug)
286294
}
295+
if cfg.Upstream.Maven != "https://maven.example.com/repository/maven-public" {
296+
t.Errorf("Upstream.Maven = %q, want %q", cfg.Upstream.Maven, "https://maven.example.com/repository/maven-public")
297+
}
298+
if cfg.Upstream.GradlePluginPortal != "https://plugins.example.com/m2" {
299+
t.Errorf("Upstream.GradlePluginPortal = %q, want %q", cfg.Upstream.GradlePluginPortal, "https://plugins.example.com/m2")
300+
}
287301
if !cfg.Gradle.BuildCache.ReadOnly {
288302
t.Error("Gradle.BuildCache.ReadOnly = false, want true")
289303
}

0 commit comments

Comments
 (0)