How can I make `gradle install` produce unique snapshots?

Following up on “Add support for specifying the local maven repo with “maven.repo.local””, I’d like to make gradle install produce unique snapshot artifacts, just like it’s done when deploying snapshots to a maven repository. Basically I want to gradle install -Dmaven.repo.local=/var/www/repo so that my users can use this repo’s unique snapshots. Right now, every call of gradle install overrides the last snapshosts (of the same version).

Can this be configured somehow?

The ‘install’ task cannot be configured to do this. It is meant to mimic the behavior of the Maven install goal which is meant for local development where keeping every unique SNAPSHOT version would result in unnecessarily bloating the local repository. If you want the behavior you get when publishing to a remote repository you can simply configure the ‘uploadArchives’ task to point to a local repository.

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file:///var/www/repo")
        }
    }
}

Thanks for your answer. How would I create an extra task for every subproject called e.g. installToLocalMavenRepo that runs mavenDeployer with the same configuration as with uploadArchives but with the repository taken from maven.repo.local? The rationale behind this is that I don’t want to install the artifacts to the local archive every time I call uploadArchives, I want to be able to explicitly trigger the deployment to the local archive (with unique snapshots).

You can specify another Upload task but you’ll likely have to duplicate the configuration from the ‘uploadArchives’ task, except the url which would be something like repositories.mavenLocal().url.

Is there a way to copy the configuration from the existing uploadArchives task and simply replace all repository definitions with one using a local path asURL?

That is the solution, placed in the root projects build.gradle, I ended up with:

subprojects {
...
	// Does install unique snapshosts (and release)s in the local maven
	// repository, unlike the 'install' task.
	// You can specify the path of the local maven repository using 'maven.repo.local', e.g.
	// gradle uploadLocal -Dmaven.repo.local=/var/www/repo
	task uploadLocal(type: Upload) {
		description "Uploads artifacts into the local maven repositories URL."
		configuration = configurations['archives']
		repositories {
			mavenDeployer {
				repository url: repositories.mavenLocal().url
			}
		}
	}
}

I just noticed that this generates POMs without the information found in the uploadArchives section. I’ve tried

mavenDeployer {
    pom.project = project.uploadArchives.repositories.mavenDeployer.pom.project
}

to copy the information over from uploadArchives. But that didn’t work, i.e. it results in

> No such property: project for class: org.gradle.api.publication.maven.internal.pom.DefaultMavenPom

Any ideas how to solve this?