ysb33r / ivypot-gradle-plugin

Ivypot is a Gradle plugin to help managing a local off-line repository for builds in restricted environments
Apache License 2.0
45 stars 14 forks source link

Maven credentials are not working #29

Closed JuergenHaug closed 5 years ago

JuergenHaug commented 6 years ago

It seems that the maven credentials are not used when accessing a maven repo:

plugins {
   id 'org.ysb33r.ivypot' version '0.6'
}

syncRemoteRepositories {
  repoRoot file('../gradle_offline_repo').absolutePath
  repositories {
    maven {
      url 'http://...'
        credentials {
          username 'user'
          password '...'
      }
    }
  }
}

dependencies {                          
  compile 'org.eclipse.etrice:org.eclipse.etrice.generator.java:1.1.2'
}

When running gradle sync (Gradle 4.3.1, Windows10 64bit, Java 1.8) the dependency cannot be resolved. Here is the debug output of gradle:

10:21:32.044 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Task :syncRemoteRepositories' started
10:21:32.046 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':syncRemoteRepositories'
10:21:32.151 [INFO] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Putting task artifact state for task ':syncRemoteRepositories' into context took 0.103 secs.
10:21:32.152 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Determining if task ':syncRemoteRepositories' is up-to-date
10:21:32.152 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Implementation for task ':syncRemoteRepositories': org.ysb33r.gradle.ivypot.OfflineRepositorySync_Decorated@a413994fb1226014355981f30b8ff143
10:21:32.152 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Action implementations for task ':syncRemoteRepositories': [org.ysb33r.gradle.ivypot.OfflineRepositorySync_Decorated@a413994fb1226014355981f30b8ff143]
10:21:32.153 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Snapshotting property repoRoot (OUTPUT) for task ':syncRemoteRepositories'
10:21:32.155 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] No discovered inputs for task ':syncRemoteRepositories'
10:21:32.155 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Up-to-date check for task ':syncRemoteRepositories' took 0.002 secs. It is not up-to-date because:
  Task has failed previously.
10:21:32.155 [DEBUG] [org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter] Ensuring directory exists for property repoRoot (OUTPUT) at C:\Dev\Tools\svn\hsl\utilities\build\gradle_offline_repo
10:21:32.156 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':syncRemoteRepositories'.
10:21:32.156 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute exec for :syncRemoteRepositories' started
10:21:32.398 [QUIET] [system.out] [syncRemoteRepositoriesConfigure] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
10:21:32.402 [QUIET] [system.out] [syncRemoteRepositoriesConfigure] :: loading settings :: file = C:\Dev\Tools\svn\hsl\utilities\build\gradle_offline_script\build\tmp\syncRemoteRepositories\ivysettings.xml
10:21:32.500 [QUIET] [system.out] [syncRemoteRepositoriesResolve] ivy.instance reference an ivy:settings defined in an other classloader.  An new default one will be used in this project.
10:21:33.039 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@61905d005 pairs: {HEAD /artifactory/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.pom HTTP/1.1: null}{User-Agent: Apache Ivy/2.2.0}{Host: <host>}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
10:21:33.059 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@202e7a839 pairs: {null: HTTP/1.1 401 Unauthorized}{Date: Tue, 17 Apr 2018 08:21:29 GMT}{Server: Artifactory/5.8.4}{X-Frame-Options: SAMEORIGIN}{X-Artifactory-Id: 83e49a5e9efcf080:6e81e18d:162486af6e3:-8000}{WWW-Authenticate: Basic realm="Artifactory Realm"}{Content-Type: application/json;charset=ISO-8859-1}{Keep-Alive: timeout=2, max=100}{Connection: Keep-Alive}
10:21:33.077 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@391bfea65 pairs: {HEAD /artifactory/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.jar HTTP/1.1: null}{User-Agent: Apache Ivy/2.2.0}{Host: <host>}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
10:21:33.098 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@4808f7d09 pairs: {null: HTTP/1.1 401 Unauthorized}{Date: Tue, 17 Apr 2018 08:21:29 GMT}{Server: Artifactory/5.8.4}{X-Frame-Options: SAMEORIGIN}{X-Artifactory-Id: 83e49a5e9efcf080:6e81e18d:162486af6e3:-8000}{WWW-Authenticate: Basic realm="Artifactory Realm"}{Content-Type: application/json;charset=ISO-8859-1}{Keep-Alive: timeout=2, max=99}{Connection: Keep-Alive}
10:21:33.227 [QUIET] [system.out] [syncRemoteRepositoriesResolve] :: problems summary ::
10:21:33.227 [QUIET] [system.out] [syncRemoteRepositoriesResolve] :::: WARNINGS
10:21:33.229 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               module not found: org.eclipse.etrice#org.eclipse.etrice.generator.java;1.1.2
10:21:33.230 [QUIET] [system.out] [syncRemoteRepositoriesResolve]       ==== maven: tried
10:21:33.230 [QUIET] [system.out] [syncRemoteRepositoriesResolve]         http://<host>/artifactory/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.pom
10:21:33.230 [QUIET] [system.out] [syncRemoteRepositoriesResolve]         -- artifact org.eclipse.etrice#org.eclipse.etrice.generator.java;1.1.2!org.eclipse.etrice.generator.java.jar:
10:21:33.230 [QUIET] [system.out] [syncRemoteRepositoriesResolve]         http://<host>/artifactory/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.jar
10:21:33.231 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               ::::::::::::::::::::::::::::::::::::::::::::::
10:21:33.231 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               ::          UNRESOLVED DEPENDENCIES         ::
10:21:33.231 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               ::::::::::::::::::::::::::::::::::::::::::::::
10:21:33.232 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               :: org.eclipse.etrice#org.eclipse.etrice.generator.java;1.1.2: not found
10:21:33.232 [QUIET] [system.out] [syncRemoteRepositoriesResolve]               ::::::::::::::::::::::::::::::::::::::::::::::
10:21:33.232 [QUIET] [system.out] [syncRemoteRepositoriesResolve]
10:21:33.234 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute exec for :syncRemoteRepositories'
10:21:33.234 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Snapshotting property repoRoot (OUTPUT) for task ':syncRemoteRepositories'
10:21:33.237 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
10:21:33.237 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':syncRemoteRepositories'
10:21:33.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Task :syncRemoteRepositories'
10:21:33.238 [null] [org.gradle.internal.progress.DefaultBuildOperationExecutor]
10:21:33.238 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Task :syncRemoteRepositories' completed
10:21:33.238 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :syncRemoteRepositories (Thread[Task worker for ':',5,main]) completed. Took 1.193 secs.
10:21:33.238 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.6 completed (1 worker(s) in use)
10:21:33.238 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on root.1.6
10:21:33.238 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on :
10:21:33.238 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':',5,main]] finished, busy: 1.193 secs, idle: 0.002 secs
10:21:33.239 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Run tasks'
10:21:33.240 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:21:33.240 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':syncRemoteRepositories'.
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > impossible to resolve dependencies:
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]           resolve failed - see output for details
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger]
10:21:33.241 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 3s
10:21:33.241 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] 1 actionable task: 1 executed

The maven repo is provided by an artifactory server and I can see following requests made:

20180417073746|1|REQUEST|ip_xxx|non_authenticated_user|HEAD|/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.pom|HTTP/1.1|401|0
20180417073746|0|REQUEST|ip_xxx|non_authenticated_user|HEAD|/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.jar|HTTP/1.1|401|0

But when I re-use the exact same repository block from above to resolve the dependencies online, it works. The second request now contains the user apparently:

20180417073506|1|REQUEST|ip_xxx|non_authenticated_user|HEAD|/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.pom|HTTP/1.1|401|0
20180417073506|7|REQUEST|ip_xxx|user|HEAD|/maven/org/eclipse/etrice/org.eclipse.etrice.generator.java/1.1.2/org.eclipse.etrice.generator.java-1.1.2.pom|HTTP/1.1|200|0
ysb33r commented 6 years ago

Can you have a look at what C:\Dev\Tools\svn\hsl\utilities\build\gradle_offline_script\build\tmp\syncRemoteRepositories\ivysettings.xml looks like and post it here? (Obviously mask out credentials before posting).

winterDroid commented 6 years ago

I face the same issue. For me it contains: <credentials host='<host>' username='<username>' passwd='<password>'/> For me it is a Nexus repository

JuergenHaug commented 6 years ago

Content of ivysettings.xml:

<ivysettings>
    <settings defaultResolver='~~~remote~~~resolvers~~~' />
    <caches
        defaultCacheDir='C:\Dev\Tools\svn\hsl\utilities\build\gradle_offline_repo'
        artifactPattern='[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'
        ivyPattern='[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'
        resolutionCacheDir='C:\Dev\Tools\svn\hsl\utilities\build\gradle_offline_script\build\tmp/ivypot/syncRemoteRepositories' />
    <credentials host='host' username='username'
        passwd='password' />
    <resolvers>
        <chain name="~~~remote~~~resolvers~~~" returnFirst="true">
            <ibiblio name='maven' m2compatible='true' root='url' />
        </chain>
    </resolvers>
</ivysettings>