|
| 1 | +# Publishing dd-trace-java Snapshots with ddprof SNAPSHOT Dependency |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This feature allows publishing dd-trace-java snapshot versions that depend on a ddprof SNAPSHOT version with an incremented minor version. |
| 6 | + |
| 7 | +**ddprof Version Calculation:** Current ddprof version `X.Y.Z` → Dependency becomes `X.(Y+1).0-SNAPSHOT` |
| 8 | + |
| 9 | +**Example:** ddprof `1.34.4` → Uses dependency `1.35.0-SNAPSHOT` |
| 10 | + |
| 11 | +### Version Qualification |
| 12 | + |
| 13 | +To avoid overwriting standard snapshot artifacts, builds with `-PuseDdprofSnapshot=true` will have a `-ddprof` qualifier added to their version: |
| 14 | + |
| 15 | +- Standard snapshot: `1.58.0-SNAPSHOT` |
| 16 | +- With ddprof snapshot: `1.58.0-ddprof-SNAPSHOT` |
| 17 | + |
| 18 | +This ensures that both versions can coexist in Maven Central Snapshots repository without conflicts. |
| 19 | + |
| 20 | +## Local Usage |
| 21 | + |
| 22 | +### Testing Dependency Resolution |
| 23 | + |
| 24 | +To verify that the ddprof snapshot version is correctly calculated and applied: |
| 25 | + |
| 26 | +```bash |
| 27 | +./gradlew -PuseDdprofSnapshot=true :dd-java-agent:ddprof-lib:dependencies --configuration runtimeClasspath |
| 28 | +``` |
| 29 | + |
| 30 | +Look for the output: |
| 31 | +- `Using ddprof snapshot version: X.Y.0-SNAPSHOT` |
| 32 | +- `Modified version for dd-trace-java: 1.58.0-SNAPSHOT -> 1.58.0-ddprof-SNAPSHOT` |
| 33 | +- `ddprof-lib: Using ddprof SNAPSHOT version X.Y.0-SNAPSHOT` |
| 34 | +- Dependency resolution showing: `com.datadoghq:ddprof:X.Y.Z -> X.(Y+1).0-SNAPSHOT` |
| 35 | + |
| 36 | +### Building with ddprof Snapshot |
| 37 | + |
| 38 | +To build the project with the ddprof snapshot dependency: |
| 39 | + |
| 40 | +```bash |
| 41 | +./gradlew build -PuseDdprofSnapshot=true |
| 42 | +``` |
| 43 | + |
| 44 | +### Publishing to Maven Central Snapshots |
| 45 | + |
| 46 | +To publish artifacts with the ddprof snapshot dependency: |
| 47 | + |
| 48 | +```bash |
| 49 | +./gradlew publishToSonatype -PuseDdprofSnapshot=true -PskipTests |
| 50 | +``` |
| 51 | + |
| 52 | +**Note:** You must have the required credentials configured: |
| 53 | +- `MAVEN_CENTRAL_USERNAME` |
| 54 | +- `MAVEN_CENTRAL_PASSWORD` |
| 55 | +- `GPG_PRIVATE_KEY` |
| 56 | +- `GPG_PASSWORD` |
| 57 | + |
| 58 | +## GitLab CI Usage |
| 59 | + |
| 60 | +### Manual Job Trigger |
| 61 | + |
| 62 | +A GitLab CI job named `deploy_snapshot_with_ddprof_snapshot` is available for manual execution. |
| 63 | + |
| 64 | +**To trigger:** |
| 65 | +1. Navigate to the pipeline in GitLab CI |
| 66 | +2. Find the `deploy_snapshot_with_ddprof_snapshot` job in the `publish` stage |
| 67 | +3. Click the manual play button to trigger it |
| 68 | + |
| 69 | +**What it does:** |
| 70 | +- Builds dd-trace-java with `-PuseDdprofSnapshot=true` |
| 71 | +- Publishes to Maven Central Snapshots repository |
| 72 | +- Produces artifacts with the ddprof snapshot dependency |
| 73 | + |
| 74 | +**When to use:** |
| 75 | +- Testing integration with unreleased ddprof features |
| 76 | +- Validating compatibility before ddprof release |
| 77 | +- Creating test builds for early adopters |
| 78 | + |
| 79 | +## Implementation Details |
| 80 | + |
| 81 | +### Files Modified |
| 82 | + |
| 83 | +1. **`gradle/ddprof-snapshot.gradle`** - Core logic for version calculation and dependency override |
| 84 | +2. **`build.gradle.kts`** - Applies the ddprof-snapshot configuration |
| 85 | +3. **`dd-java-agent/ddprof-lib/build.gradle`** - Logging for snapshot version usage |
| 86 | +4. **`.gitlab-ci.yml`** - New CI job for snapshot publishing |
| 87 | + |
| 88 | +### How It Works |
| 89 | + |
| 90 | +1. The Gradle property `-PuseDdprofSnapshot=true` activates the feature |
| 91 | +2. The configuration reads `gradle/libs.versions.toml` to get the current ddprof version |
| 92 | +3. Version is parsed using regex: `ddprof = "X.Y.Z"` |
| 93 | +4. Snapshot version is calculated: `X.(Y+1).0-SNAPSHOT` |
| 94 | +5. **The dd-trace-java version is modified** to add a `-ddprof` qualifier: |
| 95 | + - `1.58.0-SNAPSHOT` → `1.58.0-ddprof-SNAPSHOT` |
| 96 | + - This prevents overwriting standard snapshot artifacts |
| 97 | +6. Gradle's `resolutionStrategy.eachDependency` overrides all ddprof dependencies to use the snapshot version |
| 98 | +7. The build and publish proceed with the modified version and overridden dependency |
| 99 | + |
| 100 | +### Dependency Resolution Override |
| 101 | + |
| 102 | +The override is applied globally to all configurations in all projects: |
| 103 | + |
| 104 | +```groovy |
| 105 | +configurations.all { |
| 106 | + resolutionStrategy.eachDependency { DependencyResolveDetails details -> |
| 107 | + if (details.requested.group == 'com.datadoghq' && details.requested.name == 'ddprof') { |
| 108 | + details.useVersion(ddprofSnapshotVersion) |
| 109 | + details.because("Using ddprof snapshot version for integration testing") |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +This ensures that even transitive dependencies on ddprof are overridden. |
| 116 | + |
| 117 | +## Limitations |
| 118 | + |
| 119 | +- Only works with semantic versioning in format `X.Y.Z` |
| 120 | +- Requires ddprof SNAPSHOT to be published to Maven Central Snapshots repository |
| 121 | +- Cannot override local JAR files specified with `-Pddprof.jar=/path/to/jar` |
| 122 | + |
| 123 | +## Troubleshooting |
| 124 | + |
| 125 | +### "Could not find com.datadoghq:ddprof:X.Y.0-SNAPSHOT" |
| 126 | + |
| 127 | +**Cause:** The calculated ddprof snapshot version doesn't exist in Maven Central Snapshots. |
| 128 | + |
| 129 | +**Solutions:** |
| 130 | +- Verify ddprof has published the snapshot version |
| 131 | +- Check Maven Central Snapshots repository: https://central.sonatype.com/repository/maven-snapshots/ |
| 132 | +- Wait for ddprof CI to complete if a new snapshot is being published |
| 133 | + |
| 134 | +### Version not being overridden |
| 135 | + |
| 136 | +**Cause:** The property might not be correctly set or parsed. |
| 137 | + |
| 138 | +**Solutions:** |
| 139 | +- Ensure you're using `-PuseDdprofSnapshot=true` (not `-DuseDdprofSnapshot`) |
| 140 | +- Check Gradle output for "Using ddprof snapshot version" message |
| 141 | +- Run with `--info` flag to see detailed dependency resolution logs |
0 commit comments