Equivalents for mvn update and mvn install in gradle - java

I am new in gradle hence I have some questions about gradle. Before gradle I worked with maven and in maven there are some commands such as
mvn update
mvn clean install
With mvn update we download the dependency packages from internet and the other packages from the different projects.
With mvn install we create the jar, war, ear or ejb
so what are the equivalents for maven command in gradle?
mvn update ~= gradle ...
and
mvn clean install ~= gradle clean ...

Gradle will automatically fetch all required dependencies for you.
Long story short:
mvn update ~= ./gradlew build --refresh-dependencies
mvn clean install ~= ./gradlew clean build
TL;DR
To force Gradle to redownload dependencies you can execute (How can I force gradle to redownload dependencies?):
./gradlew build --refresh-dependencies
To assemble you project without executing tests (Gradle build without tests):
./gradlew assemble
To completely build you project with test execution:
./gradlew build
You can skip certain tasks by providing -x argument:
./gradlew build -x test

The equivalent to
mvn clean install
is
gradle install
what is provided by the maven plug-in of Gradle. Just add the following line to your build.gradle file:
apply plugin: 'maven'

This works for me.
./gradlew publishToMavenLocal

Here is the command:
./gradlew build

Related

What is the equvalent of npm install in maven

i am new to java and have mainly used node.js for most of my projects. I have used npm and used the npm install function to download packages. In maven, is there a similar function that easily installs packages?
mvn dependency:resolve
Is worth take a look to mvn life cycles
There's also mvn dependency:go-offline to download the dependencies and prepare to run the rest of the tasks without any connection to the internet.
I was looking for a way to install maven dependencies during a CI job, while explicitly NOT compiling the code or running the tests.
Keep all the dependencies in your pom.xml(You can think of this as package.json). If you are using an IDE like eclipse it will automatically download the dependencies for you. If you want to download the dependencies from the command line run mvn install.
You can find the corresponding XML for dependencies here https://mvnrepository.com/
Maven doesn't have an install command. Before any task you run maven checks if the project was changed and downloads any new dependency you specified from Maven Central repository.
EDIT: Maven calls the resolver for most tasks you run.

Want to build project with commandline mvn but have to use Maven update in eclipse first

I'm working with multiple projects in Eclipse. because I want to automate the building I want to script the building process.
Unfortunately I cannot do the same actions on the commandline as in Eclipse.
So a common problem is that when a new function from a referenced project is used, I cannot build the project on the commandline with mvn. I use the command:
mvn clean install -U
But this command will give a build failure until I do a Eclipse Maven Update from the eclipse GUI. After that I can build the project again.
I also tried all the other commands I came across Stackoverflow:
mvn eclipse:eclipse
mvn dependency:resolve
So I just want to that Maven Update command in eclipse from the commandline so I can build from the commandline. If anyone could tell me what I'm doing wrong that would be awesome.
Thx in advance
Update for more clarification:
The project structure is:
Rest-service, Framework-service, Framework-model
Framework-model is referenced in the pom file by Framework-service and Framework-service is referenced by Rest-service. The other projects are not relevant to the problem.
When a function is added to Framework-model and used in Rest-service it gives an compilation error in eclipse and when I build with mvn clean install -U, although Maven install in eclipse is succesful but I think it is still using the old compiled code. After a Maven Update command in eclipse the compilation error is gone. And mvn clean install -U from the commandline also works.
How could I do a Maven Update command in the commandline? If mvn clean install -U should also do a Maven Update command, what settings should I check?
Another update: So this weekend I tried different things and running mvn compile before the mvn clean install -U command gives a different output. And finds the new function. But as I read maven, I thought install should also do the previous steps. How is this possible?
Eclipse's Maven plugin uses the maven version configured in Preferences/Maven/User settings. If you have a different version of maven in your Eclipse's settings than the one on your PATH variable, you could have different outputs. Maybe try and check that.

Does maven execute chained commands

i am new to maven and I am wondering is this even possible in maven?
mvn clean install deploy
or
mvn clean compile install deploy
will maven do all the steps? thanks in advance
The short answer is yes.
Maven has the concept of a build life cycle. In the example you have given
mvn clean compile install deploy
The highest phase is deploy which includes compile and install so it's the same as mvn clean deploy.

maven build offline error- must specify a valid lifecycle phase

I am still getting the hang of Maven and spring, but am having an odd problem.
Up until a few days ago I could build maven fine by using the command:
mvn -Dmaven.test.skip=true clean install eclipse:eclipse –o
not sure what changed but i started getting the error:
BUILD FAILURE
Invalid task 'uo': you must specify a valid lifecycle phase,
or a goal in the format plugin:goal or
pluginGroupIf:pluginArtifactId:pluginVersion:goal
for mor information run with the -e switch
I tried updating all my code from SVN and got the same error. I finally completed building all packages with online with:
mvn -Dmaven.test.skip=true clean install eclipse:eclipse
which gave be BUILD SUCCESSFUL for all project packages.
Yet when I try building maven offline again i continue to get the same Build Failure error. Any thoughts?
Note: there is about 8 packages in my project and they all get the same build failure error
– character is incorrect use - instead, in your command
change this
mvn -Dmaven.test.skip=true clean install eclipse:eclipse –o
to
mvn -Dmaven.test.skip=true clean install eclipse:eclipse -o
Note: there is change in - hyphen character

How Do I Run "mvn install:install-file" in Intellij

In Netbeans, I can right click on a dependeny, and select "Manually install artifact", and it will run a maven install command like the one below:
mvn install:install-file -Dfile=AppMeasurement_SE.jar -DgroupId=com.omniture -DartifactId=AppMeasurement_SE -Dversion=1.2.4 -Dpackaging=jar
Does Intellij have a similar feature, or should I learn to love the Linux command line prompt?
There is plugin intellij-maven for this.
"intellij-maven" is a maven project which can be used to create all of
IntelliJ IDEA (Community version) build artifacts with maven and to
install them into local maven repository.

Categories

Resources