Maven liquibase plugin - maven

I am new to Maven and Liquibase. For the past couple of days, I have been playing around with liquibase without Maven. I have tried generating changelog file with a new database and an existing database. Now I am trying to implement Maven and Liquibase using the plugin.
What is the advantange of running Liquibase with Maven from the command prompt rather than just running Liquibase from the command prompt?
Once I generate the pom.xml file and have src folder ready for my current project. I have the maven liquibase plugin in the pom file and liquibase.properties in resources. Will the changeLog file automatically get created?

The reason you would want to use Liquibase through Maven is to better fit with the rest of your build configuration. If you have your project set up with Maven and your CI servers using Maven it is usually easiest to run Liquibase through Maven as well to keep things simpler for you.
There is a generateChangeLog command that you can run either through Maven or through the command line which will generate a changelog file for you based on an existing database. This is often helpful when first starting to use Liquibase.
Once you have your changelog file, you would run liqubase update through the command line or Maven to apply your changelog to a database. As you need to make changes, the recommended approach is to add new changeSets to your changelog file then run liquibase update. This tends to be safer and more consistent than making a change to the database then running liquibase diffChangeLog to capture the change back to the changelog file.

Related

Using Maven Release plug-in, update non-pom files

I have a project in which I am using maven-release-plugin to make periodic releases. I also have some script files like start.sh and stop.sh which helps in starting up the project with multiple steps using just one command. The script contains commands like, (but not limited to)
java -jar module-0.0.1-SNAPSHOT.jar
My problem is, when I run release plugin it updates all the POM files but does nothing to this script file. I want to update these script files as well along with POM files. These script files contain the version number exactly the same as pom file and the way I mentioned.
Currently, I am updating these files manually after each release.
Any help will be greatly appreciated.
Maven release plugin is indeed all about releasing the maven version. Maven as a build tool, builds the artifact and releases it.
It has nothing to do with various script files. So you should decide first of all:
Whether its a maven responsibility at all to deal with these scripts.
If so, you can create your own plugin that will do the changes. Or alternatively you can use filtering feature, Maven build helper plugin to get the access to the versioning information and assembly plugin to prepare the distribution.
Otherwise, I see 2 possible options:
Alternative 1
Rename the versioned artifact with something generic that doesn't really include any maven related versioning information.
In this case the script will always be the same and will run: java -jar my-module.jar
Alternative 2
Complicate the script so that it will find the file and resolve the version dynamically. Then it will memorize the path to the file in some variable and will run java -jar $here_is_the_resolved_file_with_version.jar

Command to update only one ChangeSet : Mvn liquibase command?

Normally to execute all the change set in a file : we use command :
mvn liquibase:update
What should I use If I want to execute to 'specific' Changeset out of many ?
Probably the best way to do this is to use labels on your changesets, and then see if you can get the maven plugin to do a deploy with labels. Labels are a fairly new feature, and it may be that the Maven plugin will need to be updated to provide support for labels. It appears that the Liquibase Maven plugin is currently using Liquibase 3.2, and labels were introduced in 3.3.

creating different types of projects using eclipse with maven

I know creating the project using maven with command prompt but if i want to import this project into eclipse i have to run some commands and it will be modified suitable for eclipse, My question is can I create different archetype projects using maven plug in to eclipse, without using maven with cmd ?
You can entirely use Eclipse without using the command prompt. Though I prefer to use both terminal and Eclipse interfaces to utilize the maven project, and is a dynamic way of development. Eclipse Mars already include Maven.
Two ways to do this:
Create a new general project, create new POM file, define dependency and build, and Eclipse will recognize to configure as Maven project without applying Eclipse Project facets.
Create a new Maven project, do not skip archetype selection and use quickstart only if creating a simple Java project with main and test source folders, define module properties (group, artifact, version, etc.), and Eclipse will configure project as Maven project without applying Eclipse Project facets.
To execute a clean install, you need to create a goal "clean install" in Eclipse Run Configuration under Maven. Caution, Eclipse use embedded Maven runtime by default so if you'd like to link with your copy of Maven, you'll need to configure Eclipse to point at your Maven installation directory.
Basically, every command you entered in command prompt need to be a goal in Eclipse Maven Run Configuration to separate yourself from using command prompt.
Example Java Maven Project:
Step 1: Create New Maven Project
The first step to begin Maven-enabled Java development without using command prompt.
Step 2: Eclipse Project Configuration
Most of the time, I usually skip this section unless special circumstance requires a working set.
Step 3: Specifying Archetype
Maven archetype quickstart comes with two source package: test and main. This is the most simplest and efficient option to begin Java development. This is equivalent to -DArchetypeArtifactId=maven-archetype-quickstart option.
Step 4: Define Archetype Parameters
Define your own archetype parameters.
Step 5: Confirm Eclipse generated a Maven-enabled Java project
Double check POM and ensure Eclipse throws no error. In this case, Eclipse warns of Java 1.5 not defined. You can fix this by specifying Java version in maven-compiler-plugin within build tag in POM but that's entirely another thread.
Step 6: Define a Maven Goal
We want to test whether Eclipse can do a "mvn clean install" by creating a new run configuration. You can see the console output in background that Eclipse successfully output Maven build.
Is this what you were asking about?

Jenkins - How to pass values from pom.xml to downstream job (free style)

I've set up 2 free style jobs, build-app and deploy-app. build-app poll the scm and builds the app, which is Maven based, and install the artifact in a web server (internal repository server), then it calls deploy-app. I would like to pass the version of the pom file () to the downstream job so it can download the correct artifact and install it on the machine. I found some answers suggesting put the version string in a properties file and use InjectEnv plugin, but I prefer read it from the pom itself. Any ideas?
Thanks!
When you build inside Maven, you have access to the pom file version as ${program.version} and can do anything you wish with it.
The downstream freestyle job can also run Maven using the same pom but a different target. The version should be the same if you take care to keep it from changing in the interim. (This suggests a procedure that should always be followed.)
So, for example, that Maven target can run a Groovy script or an Ant script that will pick up the correct file from the repo and deploy it.

How does IntelliJ create artifacts from pom files?

We have a large project that uses Maven. I don't use mvn idea:idea, I just open the maven project in IntelliJ and the majority of the work is done in terms of setting up the artifacts.
Some of the artifact settings I need to do manually as the artifact set up in IntelliJ is not identical to the one created when I run mvn clean install from the command line. Every time there is a change to the pom file I need to reapply these manual settings. (It's settings for an EJB and and EAR artifact if that changes things.)
Is there any way of getting IntelliJ to do these steps for me automatically? Or is there an article that I can read about how IntelliJ generates it's artifact settings from the pom files?
Thanks in advance :)
[EDIT]
Just to be clear, the pom file is already being automatically imported when there are changes to it. It's the manual changes that I applied after the previous import that are lost that I would like to find out how to automatically restore.
Starting from version 10.0, IDEA can be set up so to perform re-import of changes in POM files automatically.

Resources