diff --git a/src/main/java/net/flintmc/gradle/manifest/tasks/GenerateFlintManifestTask.java b/src/main/java/net/flintmc/gradle/manifest/tasks/GenerateFlintManifestTask.java index 2c993b3..198ae36 100644 --- a/src/main/java/net/flintmc/gradle/manifest/tasks/GenerateFlintManifestTask.java +++ b/src/main/java/net/flintmc/gradle/manifest/tasks/GenerateFlintManifestTask.java @@ -432,30 +432,32 @@ private Set buildMavenInstallInstructions( remoteMavenRepository = new RemoteMavenRepository(flintGradlePlugin.getHttpClient(), entry.getValue()); } - if (!internalRepository.isInstalled(artifact)) { - // The artifact is not installed already, install it - if (remoteMavenRepository == null) { - // Can't download anything in offline mode - throw new RuntimeException("Missing artifact " + artifact + " in local repository, " + - "but working in offline mode"); - } - - boolean setupSource = !downloader.hasSource(remoteMavenRepository); - if (setupSource) { - // The download has the source not set already, add it now - downloader.addSource(remoteMavenRepository); - } - - try { - // Install the artifact including dependencies - downloader.installArtifact(artifact, internalRepository); - } catch (IOException e) { - throw new FlintGradleException("Failed to install maven artifact", e); - } - - if (setupSource) { - // We added the source, clean up afterwards - downloader.removeSource(remoteMavenRepository); + synchronized (internalRepository) { + if (!internalRepository.isInstalled(artifact)) { + // The artifact is not installed already, install it + if (remoteMavenRepository == null) { + // Can't download anything in offline mode + throw new RuntimeException("Missing artifact " + artifact + " in local repository, " + + "but working in offline mode"); + } + + boolean setupSource = !downloader.hasSource(remoteMavenRepository); + if (setupSource) { + // The download has the source not set already, add it now + downloader.addSource(remoteMavenRepository); + } + + try { + // Install the artifact including dependencies + downloader.installArtifact(artifact, internalRepository); + } catch (IOException e) { + throw new FlintGradleException("Failed to install maven artifact", e); + } + + if (setupSource) { + // We added the source, clean up afterwards + downloader.removeSource(remoteMavenRepository); + } } } diff --git a/src/main/java/net/flintmc/gradle/maven/MavenArtifactDownloader.java b/src/main/java/net/flintmc/gradle/maven/MavenArtifactDownloader.java index db47c46..e340ce6 100644 --- a/src/main/java/net/flintmc/gradle/maven/MavenArtifactDownloader.java +++ b/src/main/java/net/flintmc/gradle/maven/MavenArtifactDownloader.java @@ -119,10 +119,12 @@ public synchronized void installAll(MavenArtifact artifact, SimpleMavenRepositor } if (installIfNotExists) { - // If the artifact is not installed locally, try to install it - if (!target.isInstalled(artifact) && !installArtifact(artifact, target) && artifactPom == null) { - // The artifact failed to install and there was also no POM for it - throw new MavenResolveException("Could not resolve " + artifact); + synchronized (target) { + // If the artifact is not installed locally, try to install it + if (!target.isInstalled(artifact) && !installArtifact(artifact, target) && artifactPom == null) { + // The artifact failed to install and there was also no POM for it + throw new MavenResolveException("Could not resolve " + artifact); + } } } } @@ -185,10 +187,12 @@ private void installAll(MavenPom pom, SimpleMavenRepository target) throws IOExc } } - // Try to install the dependency locally - if (!target.isInstalled(dependency) && !installArtifact(dependency, target) && dependencyPom == null) { - // The dependency had no artifact and also no POM - throw new MavenResolveException("Could not resolve " + dependency); + synchronized (target) { + // Try to install the dependency locally + if (!target.isInstalled(dependency) && !installArtifact(dependency, target) && dependencyPom == null) { + // The dependency had no artifact and also no POM + throw new MavenResolveException("Could not resolve " + dependency); + } } } }