How to run custom maven goal inside Intellij IDEA? - intellij-idea

When deploy, my command line "mvn tomcat7:deploy" instead of just "mvn deploy", is there a way to let the Maven Projects view to run the desired command line when I click deploy?

If you double click on deploy in the "Maven Projects" view, it will not launch any application server, but deploy maven artifacts on a remote server (for example a Nexus instance).
If the tomcat maven plugin is correctly configured in your pom.xml, you should expand the Plugins node under your Maven module (still in the "Maven Projects" view), expand the tomcat7 node then double click the tomcat7:deploy goal.
As a second option, you could also create a new Maven run/debug configuration and specify your own goals, this is very useful if you have to provide additional parameters such as -PmyProfile.

Related

Selenium With Jenkins- Continuous Integration and Deployment

I am new to Jenkins.
I have automation scripts designed in Selenium as Maven Project.
I am able to trigger the build (execute POM.XML from GIT repository) from Jenkins.
My current Flow is as below.
Eclipse -> GIT ->Jenkins (trigger POM.xml available in GIT).
This approach is only for the test team wherein the push the selenium code changes to GIT branch and the code is tested by executing the POM.xml file.
I want to include the Deployment step (for DEV team) in this cycle. So that the automation script executes on the latest deployment. So the flow should look something like below.
Eclipse (Dev code) -> GIT repo -> Jenkins (build) -> Jenkins (deployment in test environment) -> Jenkins (trigger POM.xml available in GIT)
This way I would be able to execute my POM.xml on every latest build.
Any help will be appreciated.
If you are a novice with Jenkins, start playing with it and download and install localy (https://jenkins.io/download/).
It is not that much to it. Here are a few simple steps.
install Jenkins, and probably have Maven, Java,
setup path in Jenkins to Maven and Java in Global Tool Configuration section ins Jenkins settings,
create a new Freestyle job,
connect to git to the desired project on git,
In section, build triggers add maven command like in console (without mvn) as "Invoke top-level Maven targets" with commands from maven like install, test etc.
Start job.
Hope this helps.
Jenkin has integration with Maven via Maven Plugin so
If you're using a freestyle project just add the relevant build step in Jenkins GUI
If you're using Jenkins Pipeline - declare your test execution via Pipeline Maven Plugin like:
node{
stage ('Automation') {
git url: 'https://path/to/your/test/repo'
withMaven(
maven: 'maven-3',
mavenSettingsConfig: 'my-maven-settings') {
sh "mvn clean test"
}
}
}
Be aware that Jenkins might not have GUI therefore you may need to either use headless browsers versions or install extra software to simulate display like Xvfb

How to update maven Project in Intellij in offline modus?

How to update maven dependencies in offline modus ? In eclipse Right click on the project -> Maven -> update project -> offline.
where to find this functionality in intellij?
I'm not familiar with Eclipse and what the operation you mention specifically does. I can tell you how IntelliJ IDEA works with maven offline.
When you toggle into "offline Mode" (via the offline button in the maven tool window), IDEA simply appends the maven --offline option to all maven command lines it runs. IDEA will update and import maven projects in the same manner as when you are "online" except that it will report any items that cannot be found in the local repository (See Working in Offline Mode in Help > Language and Framework-Specific Guidelines > Build Tools > Maven). So to update after a pom change -- regardless if you are in online or offline mode -- just run the reimport function (or let it run automatically if you have "import maven projects automatically" turned on).
Prior to going into offline mode, it is usually helpful to run the maven dependency:go-offline goal. You can either do that by creating a custom Maven Run/debug configuration, or simply running it in the terminal window.

How do you deploy a non-web Java app through CloudBees Jenkins "Deploy Now" feature?

With CloudBees now supporting deployment of Java applications, is it possible to use the post-build action in Jenkins "Deploy to CloudBees" to deploy your app? Furthermore, I'd like to use the Maven assembly plugin's jar-with-dependencies goal so that I can simply and automatically deploy my entire app to CloudBees right through Jenkins.
While the current CloudBees deployer Jenkins plugin appears to not support this, in fact it does. Here are the steps that after much trial and error worked for me:
Include the jar-with-dependencies maven plugin in your pom.xml. I used the <goal>single</goal> and <descriptorRef>jar-with-dependencies</descriptorRef> described here. That will put an additional jar file in your target folder {artifactId}-{version}-jar-with-dependencies.jar
Deploy that jar via the CloudBees API. The last line of this page explains how to do that. Specify your runnable jar, make sure the runtimeContainer=java, and the jar file to be uploaded, and it should deploy. Even though CloudBees says to use a zip file, a jar file works just fine.
Once that has been deployed once via the command line, your app ID now "remembers" those settings so that it can be done via Jenkins so long as you're doing the CloudBees Deploy to that same app. In your Jenkins job, add the "Deploy to CloudBees" Post-build action to your configuration. Click "Add Web Application" (strange, I know, since it's not a web-app! CloudBees says they will work to change that...), select First Match (even if it's a Maven project, use First Match), enter your application ID that you deployed your app to in step 2, and then enter the full name of your jar file and try your build again. It should upload your jar file and activate the instance in your CloudBees PaaS. Note that this still hard-codes the version in the jar file - I am working to see how to setup a variable for the version of the jar file so that it corresponds to the Maven build version.
Once you have it setup correctly and deployed initially with the bees sdk, it should just deploy from the deployer plugin on Jenkins as a war normally would.
Once set up, the settings that define where your main class is persist between deploys.

Make hudson automatically show pom description in its project page

I use Hudson to do continuous integration on some maven projects. For these projects, I would like to have the pom description used as content for the Hudson job description. is there a solution to automatically have this configured ?
That's a bit hard to do because Hudson needs the config so it can checkout the POM. What you can try is use the command line API to configure the project.
Another solution is to run mvn install site. That will generate the web site for the project and Hudson will present a link to it right below the description, so you can use this description:
This is a Maven project; click the link below to visit the web site.
You can just run mvn site no mvn install needed to see the link about the generated site in Hudson.

Hudson can't build my Maven 2 project because it says artifacts are missing from the repository? (they aren't)

I'm using Hudson and Maven 2 for my automated build/CI. I can build fine with maven from the command line, but when I run the same goal with Hudson, the build fails complaining of missing artifacts. I'm running Hudson as a windows XP service.
Obvious question, but have you got Hudson set up to point to the same Maven repository as your command line build? You can check this from the Hudson admin gui - look in the Maven section of the Manage Hudson page. This should have a MAVEN_HOME environment variable listed. Look in the settings.xml file under:
MAVEN_HOME\conf\settings.xml
The localRepository configuration item is the location of the Maven repository that the Hudson build is using.
Make sure you're running Hudson as the same user that you are using to run Maven from the command line. Maven creates a separate repository for each user. If you are running Hudson as a Windows service, this won't be the same user as you have logged on as and will be running "mvn" commands with. This means the artifacts in the repositories may be different.
To fix, either start Hudson manually as the user which works, or update the repository for the user which Hudson is running as.