scip-java icon indicating copy to clipboard operation
scip-java copied to clipboard

Gradle centralised repo management causes problems

Open keynmol opened this issue 2 years ago • 6 comments

Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by plugin class 'com.sourcegraph.gradle.semanticdb.SemanticdbGradlePlugin'

Stack overflow: https://stackoverflow.com/questions/69163511/build-was-configured-to-prefer-settings-repositories-over-project-repositories-b

Gradle docs: https://docs.gradle.org/7.4.2/userguide/dependency_management.html#sub:centralized-repository-declaration

keynmol avatar Aug 02 '23 13:08 keynmol

Hello. We are also experiencing an issue where placing our repository within a gradle publishing task as the gradle docs have mentioned are causing issues. Only way it works is to remove it which doesn't bode well for us. Is there any update on if this will be fixed? It's currently a blocker for us

samiabuzeineh-wk avatar Oct 10 '23 15:10 samiabuzeineh-wk

workaround:

.settings.gradle.kts

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
       // ...
    }
}

dmmedakin avatar Oct 10 '23 16:10 dmmedakin

Updating that in our settings.gradle file produced this error:

java.lang.NullPointerException: Cannot invoke "org.gradle.api.publish.PublishingExtension.getPublications()" because the return value of "org.gradle.api.plugins.ExtensionContainer.findByType(java.lang.Class)" is null
	at com.sourcegraph.gradle.semanticdb.WriteDependencies.$anonfun$printResolvedDependencies$5(SemanticdbGradlePlugin.scala:436)
	at com.sourcegraph.gradle.semanticdb.WriteDependencies.$anonfun$printResolvedDependencies$5$adapted(SemanticdbGradlePlugin.scala:421)

Does it have anything to do with the fact that this is in our settings.gradle and not in a kts file?

samiabuzeineh-wk avatar Oct 10 '23 20:10 samiabuzeineh-wk

@samiabuzeineh-wk this exception is logged, but it doesn't fail the build: https://github.com/sourcegraph/scip-java/blob/main/semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala#L450-L454

We expect some projects to fail there if they don't have publishing settings.

It's a piece of tech debt to make this exception less scary as it's not the first time I see it being interpreted as an error, whereas it really isn't :)

keynmol avatar Oct 10 '23 20:10 keynmol

Ah yes, I do see the indexing was successfully uploaded despite these "errors" :)

Thank you all for your help, that workaround seems to have done the trick!

samiabuzeineh-wk avatar Oct 10 '23 22:10 samiabuzeineh-wk

All credit to @dmmedakin!

FWIW I remember making an attempt to set this value dynamically during indexing, but Gradle wouldn't let me as some state was closed.

At some point I will restore that branch to see what's up.

keynmol avatar Oct 11 '23 06:10 keynmol