Humphrey
06/04/2023, 12:00 PMAdam S
06/04/2023, 12:41 PMsome-group-id:the-artifact:+ to always get the latest version
Just be aware that’s such dynamic versions are pretty risky, and will lead to hard-to-track issues because the version can change basically at random. You can limit some of the damage by using a prefix, something like 1.0.+, or a range (1.0, 2.0)
You can use dependency locking to protect against ‘random’ changes too https://docs.gradle.org/current/userguide/dependency_locking.html
Using a plugin that automatically updates the versions will be even more reliable https://github.com/ben-manes/gradle-versions-pluginJavier
06/04/2023, 12:54 PMJavier
06/04/2023, 12:55 PMJavier
06/04/2023, 12:56 PMJavier
06/04/2023, 12:56 PMHumphrey
06/04/2023, 1:48 PMgroup-I’d:artifact-id:+ but this is pulling only the latest release version. Not the snapshot from Nexus. And for some reason it’s getting the version 0.1298.0 from nexus but I can see version 0.1303.0 in nexus of that dependency. The former was created like 1 month ago, and the latter like few days ago.
I have changed that project to use version catalog and upgraded to latest gradle after 0.1298.0 release. Maybe I’ve missed something in the publishing part that it’s not taking the latest version anymore?
1) What is gradle looking for when searching the remote repository for a dependency?
2) in the past it was only getting the latest release, so maybe I should try using the latest.integration as version?
I’ll try tomorrow the 2nd step see if that does any difference.Humphrey
06/04/2023, 1:52 PMVampire
06/04/2023, 2:59 PM+ should be equivalent to latest.integration. It should give you the very latest version, whether snapshot or not. As your + is not even getting you your latest release version it seems there is something different broken or unexpected. Maybe you do have dependency locking in place?Humphrey
06/04/2023, 3:13 PMHumphrey
06/04/2023, 3:16 PMJavier
06/04/2023, 4:19 PMHumphrey
06/04/2023, 4:19 PMVampire
06/04/2023, 4:31 PMmaven-metadata.xml which lists versions. Check what it contains for you.Humphrey
06/04/2023, 4:32 PMVampire
06/04/2023, 4:34 PMHumphrey
06/05/2023, 7:26 AMlatest.integrationHumphrey
06/05/2023, 9:19 AMpublishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}Vampire
06/05/2023, 9:38 AMwithSourcesJar() which also adds it automatically.Humphrey
06/05/2023, 9:42 AMHumphrey
06/05/2023, 9:56 AMVampire
06/05/2023, 10:21 AMjava plugin adds the java component which you can then publish using the shown snippet which adds the mavenJava publication and configures it to publish the component which is added by the java plugin.Vampire
06/05/2023, 10:22 AMHumphrey
06/05/2023, 11:56 AMVampire
06/05/2023, 12:38 PMHumphrey
06/05/2023, 1:00 PMHumphrey
06/05/2023, 2:43 PMlatest.integration in the version.ref that is pointing to my version of the jar. (i've checked and + is doing the same thing.
The repositories are configured as follows:
val releasesRepoUrl = "<https://our-internal-nexus:8443/repository/....releases/>"
val snapshotsRepoUrl = "<https://our-internal-nexus:8443/repository/....snapshots/>"
repositories {
mavenLocal()
maven("<https://our-internal-nexus:8443/repository/public/>")
maven(releasesRepoUrl)
maven(snapshotsRepoUrl)
}
I think it should be able to find the snapshot in the snapshot repository.Humphrey
06/05/2023, 2:49 PM0.1306.0-branchname-SNAPSHOT) it seems to use the one snapshot version.Humphrey
06/05/2023, 2:50 PMversion will increase and the branch name will change.Vampire
06/05/2023, 3:05 PM0.1298.0
...:+ -> 0.1298.0
Then published 0.1306.0-branchname-SNAPSHOT
...:+ -> 0.1306.0-branchname-SNAPSHOT
Can you show an MCVE?Humphrey
06/05/2023, 3:09 PMVampire
06/05/2023, 3:10 PMHumphrey
06/05/2023, 3:10 PMVampire
06/05/2023, 3:10 PMVampire
06/05/2023, 3:11 PMVampire
06/05/2023, 3:11 PMVampire
06/05/2023, 3:12 PMAdam S
06/05/2023, 3:13 PMVampire
06/05/2023, 3:16 PM+ vs. latest.integration I assumed that should not be the problem, but yeah, try running with --refresh-dependencies to be sure. 🙂Humphrey
06/05/2023, 3:17 PMconfigurations {
all {
resolutionStrategy {
cacheChangingModulesFor(1, TimeUnit.MINUTES)
cacheDynamicVersionsFor(1, TimeUnit.MINUTES)
eachDependency {
if (group == "our-group" && listOf("artifact-1", "artifact-2").contains(name)) {
useVersion("latest.snapshot")
}
}
}
}
}Humphrey
06/05/2023, 3:17 PM--refresh-dependencies no luckHumphrey
06/05/2023, 3:19 PMVampire
06/05/2023, 3:19 PMlatest.snapshot is a thing unless you have custom stability values defined. latest.integration or +Humphrey
06/05/2023, 3:19 PMVampire
06/05/2023, 3:19 PMHumphrey
06/05/2023, 3:22 PM0.1298.0.Vampire
06/05/2023, 3:22 PMHumphrey
06/05/2023, 3:23 PMAdam S
06/05/2023, 3:24 PM--debug in there it will give a lot more information, so search through it and see if there’s anything relevantHumphrey
06/06/2023, 9:15 AMgroup:artifact:+ seem to give me always the latest version (or snapshot). I've tried with publishing to maven local.
I figured out something. Looks like that somehow only the release repository is being looked for, and not the snapshot see maven-metadata.xml below:
In nexus my release repository looks like this (i've omitted the long list of versions):
<metadata>
<groupId>my-group</groupId>
<artifactId>my-artifact</artifactId>
<versioning>
<latest>0.1298.0</latest>
<release>0.1298.0</release>
<versions>
<version>0.1280.0</version>
<version>0.1281.0</version>
<version>0.1282.0</version>
<version>0.1283.0</version>
<version>0.1284.0</version>
<version>0.1289.0</version>
<version>0.1290.0</version>
<version>0.1294.0</version>
<version>0.1295.0</version>
<version>0.1296.0</version>
<version>0.1298.0</version>
</versions>
<lastUpdated>20230516101139</lastUpdated>
</versioning>
</metadata>
and the snapshot:
<metadata>
<groupId>my-group</groupId>
<artifactId>my-artifact</artifactId>
<versioning>
<latest>0.1306.0-PR-13-SNAPSHOT</latest>
<versions>
<version>0.1306.0-bugfix-publish-SNAPSHOT</version>
<version>0.1306.0-PR-13-SNAPSHOT</version>
</versions>
<lastUpdated>20230606051712</lastUpdated>
</versioning>
</metadata>
How do I configure gradle to look for both?
I've now this in my configuration, maybe does the order matter? Should I put the snapshot first?
repositories {
mavenLocal()
maven("<https://my-nexus:8443/repository/public/>")
maven(releasesRepoUrl)
maven(snapshotsRepoUrl)
}Adam S
06/06/2023, 9:16 AMinit.gradle (or init.gradle.kts) scripts that might be adding / restricting repository contents?Humphrey
06/06/2023, 9:18 AMAdam S
06/06/2023, 9:18 AM./gradlew -q dependencyInsight --dependency my-group:my-artifact --configuration compileClassspath
(you might have to play around with the configuration)Humphrey
06/06/2023, 9:21 AMconfiguration 'compileClasspath' not found in configuration container.Adam S
06/06/2023, 9:22 AMHumphrey
06/06/2023, 9:23 AMHumphrey
06/06/2023, 9:23 AMAdam S
06/06/2023, 9:24 AM./gradlew -q :my-subproject:dependencyInsightHumphrey
06/06/2023, 9:25 AMHumphrey
06/06/2023, 9:33 AMFAILURE: Build failed with an exception.
* What went wrong:
configuration 'testCompileClasspath' not found in configuration container.
Variant apiElements:
| Attribute Name | Provided | Requested |
|------------------------------------|----------|--------------|
| org.gradle.status | release | |
| org.gradle.category | library | library |
| org.gradle.dependency.bundling | external | external |
| org.gradle.jvm.version | 11 | 11 |
| org.gradle.libraryelements | jar | classes |
| org.gradle.usage | java-api | java-api |
| org.gradle.jvm.environment | | standard-jvm |
| org.jetbrains.kotlin.platform.type | | jvm |
my-group:my-artifact:latest.integration -> 0.1298.0
\--- testCompileClasspath
A web-based, searchable dependency report is available by adding the --scan option.Humphrey
06/06/2023, 9:37 AMrepositories {
maven {
url = uri("<https://repo.mycompany.com/releases>")
mavenContent {
releasesOnly()
}
}
maven {
url = uri("<https://repo.mycompany.com/snapshots>")
mavenContent {
snapshotsOnly()
}
}
}Adam S
06/06/2023, 9:37 AMincludeGroup() tooHumphrey
06/06/2023, 10:02 AMAdam S
06/06/2023, 10:04 AMHumphrey
06/06/2023, 10:15 AMAdam S
06/06/2023, 10:15 AMHumphrey
06/06/2023, 10:16 AMAdam S
06/06/2023, 10:18 AMdependencyInsight with the --debug flag and try digging through the logs to see if there’s any hintsVampire
06/06/2023, 10:48 AMA project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.
Vampire
06/06/2023, 10:50 AMVampire
06/06/2023, 10:51 AMHumphrey
06/06/2023, 10:59 AMVampire
06/06/2023, 11:11 AM