Better way to execute code in a Maven artifact directly? (no project) - java

I really like the ability to be able to take a Maven artifact that has some useful code in it that can be run directly from the command line. You could run utilities directly from the command line or scripts without first having to download/install anything.
Right now I'm doing it like this inside a script:
mvn -q dependency:copy -Dartifact=${GROUPID}:${ARTIFACTID}:${VERSION}:pom -DoutputDirectory=${TARGET}
mvn -q dependency:copy -Dartifact=${GROUPID}:${ARTIFACTID}:${VERSION} -DoutputDirectory=${TARGET}
mvn -q dependency:copy-dependencies -f ${TARGET}/${ARTIFACTID}-${VERSION}.pom -DoutputDirectory=dependencies
java -cp ${TARGET}/\*:${TARGET}/dependencies/\* ${MAIN}
I tried doing it with the exec plugin, hoping that I could condense that into a single mvn call, but I wasn't able to get it to work.
Is there a better way to do this? (Like in a single mvn call)

Related

configure maven command line args in settings.xml or set in intellij Idea IDEA

I have multiple projects where I have to pass the following parameters each time.
-Djavax.net.ssl.trustStore=C:\VALUE
-P aws-build
-DskipTests=TRUE
The complete command is:
mvn -Djavax.net.ssl.trustStore=C:\VALUE clean install -P aws-build -DskipTests=TRUE
I am trying to configure it permanently so that I won't have to put it each time I do mvn clean install
I am looking to put settings in settings.xml or anywhere in intellij or any working solution is welcome. The objective is if I run mvn clean install, it should pick up those parameters automatically. Thanks!
Got help from a friend:
In Intellij Idea we can do this:
open pom.xml file -> run maven -> new goal -> add the followings in command line:
-Djavax.net.ssl.trustStore=C:\VALUE clean install -P aws-build -DskipTests=TRUE
->OK.

Maven param that contains spaces in jenkins declarative pipeline

Let's say that we have a jenkins pipeline that at some point we execute a maven parameterized build:
sh "mvn clean install -DparameterType=${parameter}"
What if the parameter's value contained spaces? Eg the value was "test param".
When running on IDE, this of course works:
mvn clean install -DparameterType="test param"
But if we do sth similar inside the pipeline, like
sh "mvn clean install -DparameterType=\"${parameter}\""
or
sh "mvn clean install -DparameterType=""${parameter}""
it doesn't and the param is passed like
-DparameterType=test param
which is not good for maven. Any ideas please?
You can try using:
sh """
mvn clean install -DparameterType=\"${parameter}\"
"""

Using mvn clean install from cmd, while running the app from intellij its seems like it rebuilding it

I'm trying to automate some mvn commands to set up the dev env in IntelliJ.
I'm running from cmd:
mvn clean install -DskipTests -P profile1,profile2
When it finish, I'm running the app from IntelliJ, it seems like IntelliJ is compelling and building it again before it runs.
Is there a way to add flags to the cmd command in order to save the step of IntelliJ compiling & building it?

Maven - Check a local dependency on Windows

I'm must verify a maven local dependency into a python script. I succeed to do it on linux using this command (from this thread).
mvn dependency:get -Dartifact=g:a:v -o -DrepoUrl=file://~/.m2/repository
My problem is that I'm working with a team using Windows, Linux and Mac, under Windows I'm unable to execute this command, the repo path is the one from mvn configuration maybe the problem is coming from the way I'm calling it as parameter.
mvn dependency:get -Dartifact=g:a:v -o -DrepoUrl=file://C:\Users\user\.m2\repository
Is someone already use this command on Windows and have any hints to solve this problem ?
Thank you .
Finally I reached a solution.
I'm not sure to understand but on windows firstly I must run :
mvn dependency:get
before running :
mvn dependency:get -Dartifact=g:a:v -o
I think the problem about 'dependency plugin' is solved by the first command.

maven - Instruct mvn to find POM upon the path [duplicate]

Supposing my maven project is located in /some/location/project and my current location is /another/location/ how can I run maven build without changing to project location cd /some/location/project?
You can use the parameter -f (or --file) and specify the path to your pom file, e.g. mvn -f /path/to/pom.xml
This runs maven "as if" it were in /path/to for the working directory.
I don't think maven supports this. If you're on Unix, and don't want to leave your current directory, you could use a small shell script, a shell function, or just a sub-shell:
user#host ~/project$ (cd ~/some/location; mvn install)
[ ... mvn build ... ]
user#host ~/project$
As a bash function (which you could add to your ~/.bashrc):
function mvn-there() {
DIR="$1"
shift
(cd $DIR; mvn "$#")
}
user#host ~/project$ mvn-there ~/some/location install)
[ ... mvn build ... ]
user#host ~/project$
I realize this doesn't answer the specific question, but may provide you with what you're after. I'm not familiar with the Windows shell, though you should be able to reach a similar solution there as well.
Regards
For me, works this way: mvn -f /path/to/pom.xml [goals]
You can try this:
pushd ../
maven install [...]
popd
If you want to run maven without this command "mvn -f path/to/pom.xml" you can right click on your folder project (in intellij) and click on Rebuild module "name of your artifactId" (corresponding in your pom.xml). It worked for me.

Categories

Resources