While publishing to a maven repository, M2_REPO is ignored


(Justin Ryan) #1

I’m publishing to oss.sonatype.org, which requires a very specific parent pom for published modules. During the publish, it seems as if Gradle is calling out to maven-ant-tasks to do the publish, which will try to verify the parent pom. To do that it has to download the parent poms, this is where the error starts. I’m running on Jenkins, where the user.home is read only, hence no job can write to ~/.m2/repository. This is wise since Maven has known issues with concurrent writes to its local repository (yeah Gradle cache! which doesn’t have this problem). The typical way around this is to set M2_REPO as an environment variable, except that doesn’t help with the gradle, see stacktrace below.

I found that org.apache.maven.artifact.antAbstractArtifactTask#initSettings() merges a userSettingsFile and a globalSettingsFile, and once done it runs this code:

if ( StringUtils.isEmpty( settings.getLocalRepository() ) )
        {
            String location = newFile( System.getProperty( "user.home" ), ".m2", "repository" ).getAbsolutePath();
            settings.setLocalRepository( location );
        }

You can see that if the localRepository isn’t set, it’ll default to ${user.home}/.m2/repository which doesn’t work in a shared environment. The fallback is to use a global settings.xml file, but I don’t believe this to be a general solution since it involves telling everyone using Jenkins to make a custom settings.xml for every slave. The userSettings comes from EmptyMavenSettingsSupplier, which is eponymously empty.

The real fix is to modify maven-ant-tasks to respect M2_REPO, I’ve filed a ticket for it (https://jira.codehaus.org/browse/MANTTASKS-231). Even if I submit a fix to it, I don’t expect a new release within the next year. From the Gradle side, there looks like hints in MaybeUserMavenSettingsSupplier with mavenFileLocations that other settings files could be provided, but I can’t figure out how to hook into it. I’d also not want to mess with the maven settings too much from my build script, I’d like to actually fix this in Gradle directory for that it helps all Jenkins users (Gradle NEEDS to work well in a CI environment).

I’d suggest a fix by modifying EmptyMavenSettingsSupplier to set basic environment settings like localRepository and interactiveMode, defaulting to something relative to GRADLE_USER_HOME for localRepository. This might not be exactly what user’s expect, if they want to share their ~/.m2/repository. I get that, but neither Gradle can’t guarantee concurrent builds being stable if one of its components (maven-ant-tasks) is going to be using a shared resource. A user’s global settings.xml will still be in place to for a user to override anything if they need to. The real goal here is gain concurrency stability by localizing maven’s localRepository via a constructed maven settings.xml file, without having to check one into every Gradle project.

Ideas?

Stacktrace:

23:48:23.244 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.246 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
23:48:23.247 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.247 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
23:48:23.248 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':template-client:uploadMavenCentral'.
23:48:23.249 [ERROR] [org.gradle.BuildExceptionReporter] > Could not publish configuration ':template-client:archives'.
23:48:23.253 [ERROR] [org.gradle.BuildExceptionReporter]
  > Unable to initialize POM pom-default.xml: Cannot find parent: org.sonatype.oss:oss-parent for project: com.netflix.gradle-template-master:template-client:jar:1.4 for project com.netflix.gradle-template-master:template-client:jar:1.4
23:48:23.254 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.254 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
23:48:23.257 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':template-client:uploadMavenCentral'.
23:48:23.257 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:68)
23:48:23.258 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
23:48:23.259 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)
23:48:23.259 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)
23:48:23.260 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200)
23:48:23.261 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172)
23:48:23.262 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
23:48:23.263 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:137)
23:48:23.263 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
23:48:23.264 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
23:48:23.264 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
23:48:23.265 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
23:48:23.266 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
23:48:23.267 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
23:48:23.268 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
23:48:23.269 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
23:48:23.270 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247)
23:48:23.271 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)
23:48:23.272 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)
23:48:23.273 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)
23:48:23.274 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)
23:48:23.275 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
23:48:23.275 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
23:48:23.276 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
23:48:23.277 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
23:48:23.278 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111)
23:48:23.279 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
23:48:23.280 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109)
23:48:23.281 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:129)
23:48:23.281 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
23:48:23.282 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
23:48:23.283 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
23:48:23.284 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
23:48:23.284 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
23:48:23.285 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
23:48:23.286 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
23:48:23.287 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
23:48:23.288 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)
23:48:23.288 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
23:48:23.289 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
23:48:23.290 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
23:48:23.291 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
23:48:23.291 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
23:48:23.292 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
23:48:23.293 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
23:48:23.294 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
23:48:23.294 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)
23:48:23.295 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)
23:48:23.296 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
23:48:23.297 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)
23:48:23.298 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
23:48:23.298 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
23:48:23.299 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.Main.doAction(Main.java:48)
23:48:23.300 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
23:48:23.300 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.Main.main(Main.java:39)
23:48:23.301 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
23:48:23.302 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
23:48:23.303 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
23:48:23.303 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
23:48:23.304 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
23:48:23.305 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
23:48:23.306 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.artifacts.PublishException: Could not publish configuration ':template-client:archives'.
23:48:23.307 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactPublisher.publish(ErrorHandlingArtifactPublisher.java:35)
23:48:23.307 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.tasks.Upload.upload(Upload.java:63)
23:48:23.308 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:196)
23:48:23.309 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:102)
23:48:23.310 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:99)
23:48:23.310 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.tasks.Upload_Decorated.invokeMethod(Unknown Source)
23:48:23.311 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
23:48:23.312 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(AnnotationProcessingTaskFactory.java:150)
23:48:23.313 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(AnnotationProcessingTaskFactory.java:145)
23:48:23.314 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:472)
23:48:23.315 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:461)
23:48:23.315 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:60)
23:48:23.316 [ERROR] [org.gradle.BuildExceptionReporter]
... 60 more
23:48:23.317 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: Unable to initialize POM pom-default.xml: Cannot find parent: org.sonatype.oss:oss-parent for project: com.netflix.gradle-template-master:template-client:jar:1.4 for project com.netflix.gradle-template-master:template-client:jar:1.4
23:48:23.317 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.Pom.initialiseMavenProject(Pom.java:217)
23:48:23.318 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.AbstractArtifactTask.initializePom(AbstractArtifactTask.java:527)
23:48:23.319 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.InstallDeployTaskSupport.initializePom(InstallDeployTaskSupport.java:59)
23:48:23.320 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.DeployTask.doExecute(DeployTask.java:98)
23:48:23.320 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.publication.maven.internal.ant.CustomDeployTask.doExecute(CustomDeployTask.java:41)
23:48:23.321 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.AbstractArtifactTask.execute(AbstractArtifactTask.java:751)
23:48:23.322 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.publication.maven.internal.ant.AbstractMavenResolver.execute(AbstractMavenResolver.java:195)
23:48:23.323 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.publication.maven.internal.ant.AbstractMavenResolver.commitPublishTransaction(AbstractMavenResolver.java:186)
23:48:23.324 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyDependencyPublisher$Publication.publishTo(DefaultIvyDependencyPublisher.java:96)
23:48:23.324 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyDependencyPublisher.publish(DefaultIvyDependencyPublisher.java:54)
23:48:23.325 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.IvyBackedArtifactPublisher.publish(IvyBackedArtifactPublisher.java:71)
23:48:23.326 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactPublisher.publish(ErrorHandlingArtifactPublisher.java:33)
23:48:23.327 [ERROR] [org.gradle.BuildExceptionReporter]
... 71 more
23:48:23.328 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.apache.maven.project.ProjectBuildingException: Cannot find parent: org.sonatype.oss:oss-parent for project: com.netflix.gradle-template-master:template-client:jar:1.4 for project com.netflix.gradle-template-master:template-client:jar:1.4
23:48:23.329 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396)
23:48:23.329 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823)
23:48:23.330 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:508)
23:48:23.331 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
23:48:23.331 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.ant.Pom.initialiseMavenProject(Pom.java:211)
23:48:23.332 [ERROR] [org.gradle.BuildExceptionReporter]
... 82 more
23:48:23.333 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.apache.maven.project.ProjectBuildingException: POM 'org.sonatype.oss:oss-parent' not found in repository: Unable to download the artifact from any repository
23:48:23.334 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.335 [ERROR] [org.gradle.BuildExceptionReporter]
 org.sonatype.oss:oss-parent:pom:7
23:48:23.335 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.336 [ERROR] [org.gradle.BuildExceptionReporter] from the specified remote repositories:
23:48:23.337 [ERROR] [org.gradle.BuildExceptionReporter]
 central (http://repo1.maven.org/maven2)
23:48:23.338 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.339 [ERROR] [org.gradle.BuildExceptionReporter]
for project org.sonatype.oss:oss-parent
23:48:23.340 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:605)
23:48:23.340 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1392)
23:48:23.341 [ERROR] [org.gradle.BuildExceptionReporter]
... 86 more
23:48:23.342 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable to download the artifact from any repository
23:48:23.342 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.342 [ERROR] [org.gradle.BuildExceptionReporter]
 org.sonatype.oss:oss-parent:pom:7
23:48:23.343 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.343 [ERROR] [org.gradle.BuildExceptionReporter] from the specified remote repositories:
23:48:23.343 [ERROR] [org.gradle.BuildExceptionReporter]
 central (http://repo1.maven.org/maven2)
23:48:23.344 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.345 [ERROR] [org.gradle.BuildExceptionReporter]
 23:48:23.345 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:228)
23:48:23.346 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:90)
23:48:23.347 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:558)
23:48:23.348 [ERROR] [org.gradle.BuildExceptionReporter]
... 87 more
23:48:23.348 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.apache.maven.wagon.ResourceDoesNotExistException: Unable to download the artifact from any repository
23:48:23.349 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact(DefaultWagonManager.java:404)
23:48:23.349 [ERROR] [org.gradle.BuildExceptionReporter]
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:216)
23:48:23.349 [ERROR] [org.gradle.BuildExceptionReporter]
... 89 more

(Justin Ryan) #2

I realized later that M2_REPO is not a standard environment variable, but the point is still valid: localDirectory should be set to a safe value by default in Gradle.

I can modify the Jenkins Gradle plugin to send a property or Environment variable to a proper M2_REPO location, but I need Gradle to then use it somewhere.


(Luke Daley) #3

Still investigating, but just wanted to point out that you don’t need to use the Sonatype parent POM to publish there. I’ve published a few projects there that do not have this.


(Luke Daley) #4

We do respect ‘M2_HOME’. Does that work for you?

You can set it to a build agent working space to avoid concurrency issues.


(Justin Ryan) #5

I stuck to the “book” (https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-7a.1.POMandsettingsconfig) and didn’t even think to deviate. Now looking at it, it seems to be used to add a few maven plugins which I can’t use since I’m coming from Gradle. I’ll give it a try, it’ll let me rip out a few hacks that I currently have.


(Justin Ryan) #6

I’ll agree that M2_HOME is respected, which is a backdoor that I’m using. For reference, this is what I have to do to set a working-space relative directory:

mkdir -p $WORKSPACE/conf
if [[ ! -f "${WORKSPACE}/conf/settings.xml" && -n "${M2_REPO}" ]]; then
    echo "<settings><localRepository>$M2_REPO</localRepository></settings>" > "${WORKSPACE}/conf/settings.xml"
    echo "*" > "${WORKSPACE}/conf/.gitignore"
fi

You can see that just using M2_HOME isn’t perfect. I’ll have to migrate that logic to a gradle init script. I’d really like access to EmptyMavenSettingsSupplier, since it’s already doing the bulk of the work already.


(Luke Daley) #7

Isn’t the local repo relative to M2_HOME by default?


(Justin Ryan) #8

Not with maven-ant-tasks at least. Look at the code snippet in the original post. It defaults to user.home and NOT M2_HOME as the root of .m2/repository.


(Luke Daley) #9

I’m wondering whether the simplest solution might be just to respect M2_REPO. This could also form the basis of a workaround for GRADLE-2349.