When I do a ./gradlew publishToMavenLocal it publishes to my default maven home directory of: ~/.m2.
I would instead like to publish to a custom maven repository path.
To do with with mvn command line, you can specify the command line -Dmaven.repo.local=$HOME/.my/other/repository
(See: https://stackoverflow.com/a/7071791/1174024)
But what about when publishing with Gradle? Is there a way to publish to a custom path by using an environment variable, or something similar?
You can add a system property maven.repo.local with the path.
Example:
./gradlew -Dmaven.repo.local=/path/to/local/repo publishToMavenLocal
Source: https://github.com/gradle/gradle/blob/0cb6116e150ec397f2e6c935ab4a851b48d2cf67/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/mvnsettings/DefaultLocalMavenRepositoryLocator.java#L46
Note that the same thing does NOT work if you specify as a gradle project -P property. Only reads system properties.
Related
Does running mvn with no arguments in the directory of the project result in the default lifecylce being executed for that project?
What if a profile is specified with the -P flag? does it execute the default lifecycle and binds any plugins in the profile to the phases they declare?
On your pom you can use the tag defaultGoal to specify the goal that should be executed by maven if you do not specify nothing on the command line.
See POM reference
I am using mvn archetype:generate -B ... to generate a maven project.
It places the generated project in the current working directory.
Can this be customized to place the generated project in a directory I specify? I don't see any options to do so in the command line --help menu.
You cannot specify a directory for archetype:generate, this plugin always targets the current working directory.
The Maven Archetype docs suggest using the basedir parameter. Something like this perhaps:
mvn archetype:generate
-DgroupId=foo
-DartifactId=bar
-Dbasedir=/some/other/directory
But, unfortuntately that doesn't work, even with that parameter specified the archetype is generated into the current working directory. Looking at the Maven Archetype JIRA I can see that there is an open issue for this:
https://issues.apache.org/jira/browse/ARCHETYPE-311
This issue has been open since April 2010 and it has been raised against version 2.2.0 of the archetype plugin and I have just verified that this issue still exists with in latest version of the archetype plugin, the following command completed but created bar in the current working directory rather than in /some/other/path ...
mvn org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
-DgroupId=bar
-DartifactId=foo
-Dbasedir=/some/other/directory
So, if you want to use archetype:generate and you want the generated project to exist somewhere else then I think you might have to write a simple script which ...
Invokes the plugin
Moves the created directory to your desired location once the plugin has finished running
-Dbasedir doesn't work.
You could specify output directory by passing -DoutputDirectory=/some/other/directory
Here's the documentation
https://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html
I'm using mvn install to build the .hpi to my plugin for Jenkins. This puts a .hpi in the target folder.
What I would like to do is if the build is successful, copy the hpi-file to a specific folder. Is it possible to do both these task with one Maven command using only the terminal/command prompt?
edit
My POM can be seen here.
https://github.com/MarkusDNC/plot-plugin/blob/master/pom.xml
There is now way to copy file through MVN CMD.
After that being said - You have 2 options:
1.) using a simple shell/batch step to copy.
2.) You need to Add another build step for maven but you will also need a new pom.xml file and use maven-antrun-plugin
I have a plugin which can run either using a pom.xml or without (depends upon the version of the artifact we're building: new versions go without a pom. Strange, I know).
I want to have that plugin run in Jenkins.
But when creating a maven project, I have to set a pom (or as a default, Jenkins suppose there is one in the base folder given).
Question: Is it possible to configure Jenkins to not use a pom when there is none?
As per my comment, you should use a Jenkins freestyle project build in this case, in order to have more flexibility and avoid the default assumptions of a Jenkins Maven build.
In such a build, you can then configure a build step executing a shell or a Windows command (depending on the Jenkins server OS).
Indeed, in the Jenkins Maven build, a pom file is always required, as mentioned in the help support of the Configuration > Build > Root Pom entry
If your workspace has the top-level pom.xml in somewhere other than the 1st module's root directory, specify the path (relative to the module root) here, such as parent/pom.xml.
If left empty, defaults to pom.xml
I am learning to use git and gradle to build Spring 3.2 on my local system.
I cloned the git repo and used the gradlew command to start the build like so:
gradlew build
I also have the GRADLE_HOME set up and added GRADLE_HOME/bin to my PATH variable.
Every time I start up the build I see a .gradle directory being created in my directory C:\Users\Ayusman and it seems to download gradle binaries.
My questions:
Since I already have gradle installed on my system; why does it have to download gradle?
Can I force gradle to put my dependencies in a specific directory instead of the users folder (like I can specify in maven)?
Can gradle be pointed to pull from a local repo instead of internet?
ad 1. In order to build with your locally installed Gradle, you have to invoke gradle rather than gradlew. The purpose of gradlew (called the Gradle Wrapper) is for everybody to use the same Gradle version and not having to install Gradle manually.
ad 2. To change where Gradle puts dependencies (and other global information), you can set the GRADLE_USER_HOME environment variable.
ad 3. You just need to add another repository declaration to build.gradle. Something like:
allprojects {
repositories {
maven {
url "http://..."
}
}
}
If you want to use this repository for all your builds, you can put the same declaration into ~/.gradle/init.gradle.
Because gradlew invokes the gradle wrapper, which downloads the version of gradle that the build script has been written for, instead of using your version, which might not be compatible. It does that only once, and then reuses the downloaed version. If you want to use your version of gradle, use the gradle command rather than gradlew, but it might not work if you don't have the appropriate version.
AFAIK, this is done by defining the GRADLE_USER_HOME environment variable.
See http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:repositories