Liquibase and JAR dependencies - liquibase

I'm new to Liquibase but I've got it set up and it's working OK for me, but I've manually downloaded all dependent JAR files to get it working.
Now I want to set up a pom.xml and let Maven worry about downloading dependences. For some reason I can't get that to work at all. Maven runs and finds what it thinks are all the dependencies, but then Liquibase immediately crashes every time it starts. With version 3.5.5 up through 3.8.0 it crashes with NoClassDefFoundError on org/slf4j/LoggerFactory; on 3.8.1 and above it fails with the same error on ch/qos/logback/core/Context. I've triple-checked my classpath settings and I'm sure they are correct.
So my question is this: Fundamentally, should it be possible to set up a dependency on liquibase-core in a pom.xml file, let Maven download all dependencies, and use those and only those dependencies in the java call (other than the JDBC driver, of course)?
Everything I know about Maven tells me that this should work, but I've been trying for hours and for the life of me cannot get Liquibase to work with the dependent JARs which Maven downloads. And strangely, it does seem to download the JARs I would have expected are missing: slf4j-api (1.7.25) and logback-core (1.2.3). but for whatever reason it seems to be calling methods which aren't defined in them (version skew somehow?).
Here is my "pom.xml" file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myproject</groupId>
<artifactId>myapp-lib</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.8.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifactItems>
<artifactItem>
<groupId>
GetLiquibaseJars
</groupId>
<artifactId>GetLiquibaseJars</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>[ packaging ]</type>
<outputDirectory>${MYAPP_ROOT}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When run, that downloads:
jaxb-api-2.3.0.jar
logback-classic-1.2.3.jar
liquibase-core-3.8.7.jar
slf4j-api-1.7.28.jar
logback-core-1.2.3.jar
so logback-core is available. Here's my Java call:
java -classpath "/home/myself/proj/my_app/lib/jaxb-api-2.3.0.jar:\
/home/myself/proj/my_app/lib/liquibase-core-3.8.7.jar:\
/home/myself/proj/my_app/lib/logback-core-1.2.3.jar:\
/home/myself/proj/my_app/lib/logback-classic-1.2.3.jar:\
/home/myself/proj/my_app/lib/slf4j-api-1.7.28.jar" \
-jar /home/myself/proj/my_app/lib/liquibase-core-3.8.7.jar \
--classpath=/home/myself/proj/my_app/links/sybase-linux/jConnect-6_0/classes/jconn3.jar \
--url=jdbc:sybase:Tds:mydbserver.mycompany.com:1234 \
--defaultSchemaName=dbo --username=my_user \
--password=my_pwd \
--changeLogFile=/home/myself/proj/my_app/db/changelog.xml \
--logLevel=info status
The exception I get is:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/Context
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.Context
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I've confirmed the jar file are readable, and as far as I can tell this "Context" class is defined in logback-core v1.2.3.
Update: Interestingly, if I replace the "-jar /home/myself/proj/my_app/lib/liquibase-core-3.8.7.jar" with a call to the Main, i.e. "liquibase.integration.commandline.Main", it works fine. But calling the main Liquibase core JAR file as a runnable jar with "-jar" seems to cause Java to completely ignore the entire classpath, and crash on the first external dependency it sees.

Related

Tycho compiler plugin fail to generate lombok functions

We have an OSGI framework and we are introducing Lombok in it.
In the pom.xml we added the dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
but mvn install compilation still fail with
org.eclipse.tycho:tycho-compiler-plugin:2.0.0:compile (default-compile) on project XXX: Compilation failure: Compilation failure:
[ERROR] ...
[ERROR] ...
[ERROR] The method setXXX(String) is undefined for the type XXX
From Eclipse, everything compile and is working fine.
lombok.jar was also added to Bundle-ClassPath of MANIFEST.MF
We added the annotationProcessorPaths to the pom.xml without success
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
EDIT
Even when configuring tycho compiler it doesn't work
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<source>${compileSource}</source>
<target>${compileSource}</target>
<compilerArguments>
<processor> lombok.launch.AnnotationProcessorHider$AnnotationProcessor
</processor>
</compilerArguments>
</configuration>
</plugin>
when I added set MAVEN_OPTS="-javaagent:C:\\Eclipse\\lombok.jar" compilation worked, so is there any way to add this argument inside the compiler configuration in the pom.xml with a generic path to the lombok.jar
I'm succeeded in using Lombok within a eclipse plugin, and building the plugin with tycho.
https://github.com/poul-m/tycho-lombokizer
when I added set MAVEN_OPTS="-javaagent:C:\Eclipse\lombok.jar" compilation worked, so is there any way to add this argument inside the compiler configuration in the pom.xml with a generic path to the lombok.jar
I was able to create .mvn/jvm.config in my project directory and configure a path relative to the project directory in there. Maven Tycho then successfully build my project with Lombok annotations:
This would be the content of the jvm.config:
-javaagent:project/relative/path/to/lombok.jar
https://maven.apache.org/configure.html
Edit: I only tried it with Maven Tycho 2.7.0

How To Build Child Modules In Tycho

I have a multi-module Tycho build with a target definition file. The target definition is defined in it's own project (ID: org.acme.project.target, packaging type: pom) like this:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>platform_rcp.target</file>
<type>target</type>
<classifier>platform_rcp</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And the Maven parent refers to this target platform like this:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<resolver>p2</resolver>
<target>
<artifact>
<groupId>${project.groupId}</groupId>
<artifactId>org.acme.project.target</artifactId>
<version>${project.version}</version>
<classifier>platform_rcp</classifier>
</artifact>
</target>
</configuration>
</plugin>
This setup works as long as I build the parent project. When I build one of the child modules, even if this project duplicates the reference to the target platform OR even when I build the parent with mvn install -pl org.acme.project I get the following exception:
[ERROR] Internal error: java.lang.RuntimeException: Could not resolve target platform specification artifact myGroup:org.acme.project.target:target:platform_rcp:2.3.0-SNAPSHOT -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: Could not resolve target platform specification artifact myGroup:org.acme.project.target:target:platform_rcp:2.3.0-SNAPSHOT
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
Even the Tycho example doesn't work for me, but brings the same error message (Could not resolve target platform specification artifact example.group:mars:target:1.0.0-SNAPSHOT).
I thought this question was similar, but my setup is exactly what is said to work in the answer.
What did I do wrong?
(The actual problem in question is that Eclipse Mars can't run integration tests, so I can only use Tycho to run them, which needs a long time when Tycho builds all modules.)
even when I build the parent with mvn install -pl org.acme.project I get the following exception:
Have you tried prepending the target platform project to the list of -pl arguments: mvn install -pl :mars,org.acme.project
I use this all the time.

Maven plugin dependencies are ignored

I created this profile for deploying artifacts on the server via SCP. I know Ant's scp task is optional, therefore I've added the dependencies.
<profiles>
<profile>
<id>remote-deploy</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>scp</id>
<phase>install</phase>
<configuration>
<tasks>
<scp .../>
<sshexec .../>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.42</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
However, when I run the profile, I end up with
An Ant BuildException has occured:
Problem: failed to create task or type
scp Cause: the class
org.apache.tools.ant.taskdefs.optional.ssh.Scp
was not found.
This looks like one of Ant's optional components. Action: Check
that the appropriate optional JAR
exists in
-ANT_HOME\lib
-the IDE Ant configuration dialogs
Do not panic, this is a common
problem. The commonest cause is a
missing JAR.
This is not a bug; it is a
configuration problem
Is it possible maven wasn't able to download those dependencies or it just ignores them?
The problem was Maven (2.2.1) didn't download the dependencies. I've found out after I upgraded Maven to version 3. For some reason,the new version downloaded the plugin dependencies and it miraculously started to work.
I have a suspicion the problem was in old version Maven's settings - pluginRepository wasn't configured.
It is likely that maven has downloaded the jars but it is not in ant's classpath. If the objective is to deploy the artifacts using maven, you should probably use Maven Deploy Plugin. What you are doing seems to be a roundabout way.
There is a maven-antrun-plugin bug entry, that could explain why this is happening in Maven-2, they also describe workarounds
In multi-module builds, if there are multiple poms configuring the maven-antrun-plugin, the first(?) seems to win, so that the ones later in the build chain reuse the antrun config from earlier poms, thus missing out on stuff that is different ...
In my problem case, I opted to use Maven-3, where the issue seems to be fixed, instead of workarounds with Maven-2. This had the additional advantage of the build to also speed up - now taking 6min instead of the 10min before.
However, if Maven-3 is not possible for you, I'd try the workarounds...

Flex-Mojo/Flex-compiler version issues with Flex 4.1 and maven2

My projects UI is built using Flex4.1..I am using maven2 and trying to figure out which flex-mojo version should I use for compiling.
I tried with the following,
<flex.sdk.version>4.1.0.16076</flex.sdk.version>
<flex.mojo.version>3.6.1</flex.mojo.version>
but am running into issues..
[INFO] Flex compiler and flex framework versions doesn't match. Compiler: '3.2.0.3958' - Framework: '4.1.0.16076'.
You can use 'ignoreVersionIssues' to disable this check. Please refer to Flexmojos maven doc.
If you prefer fixing it instead of ignoring, take a look at: https://docs.sonatype.org/display/FLEXMOJOS/How+to+set+Flex+SDK+version
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Flex compiler and flex framework versions doesn't match. Compiler: '3.2.0.3958' - Framework: '4.1.0.16076'.
You can use 'ignoreVersionIssues' to disable this check. Please refer to Flexmojos maven doc.
If you prefer fixing it instead of ignoring, take a look at: https://docs.sonatype.org/display/FLEXMOJOS/How+to+set+Flex+SDK+version
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:699)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:540)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:519)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoFailureException: Flex compiler and flex framework versions doesn't match. Compiler: '3.2.0.3958' - Framework:
'4.1.0.16076'.
You can use 'ignoreVersionIssues' to disable this check. Please refer to Flexmojos maven doc.
Not too sure why it is referring the compiler version as '3.2.0.3958' although I have defined the compiler version same as the "flex.sdk.version". My plugin looks like
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flex.mojo.version}</version>
<extensions>true</extensions>
<configuration>
<!--
<linkReport>true</linkReport>
<configurationReport>true</configurationReport>
-->
<locales>
<param>en_US</param>
</locales>
<sourcePaths>
<path>${project.build.sourceDirectory}</path>
</sourcePaths>
<contextRoot>${project.parent.artifactId}</contextRoot>
<showWarnings>false</showWarnings>
<debug>true</debug>
<keepGeneratedActionscript>false</keepGeneratedActionscript>
<incremental>true</incremental>
<!-- <ignoreVersionIssues>true</ignoreVersionIssues> -->
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flex.sdk.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
Can anybody help??
Well, I spent the better part of a day trying to figure out the same thing. Finally, I ran across this:
Since flexmojos is an extension, it will be downloaded before the build
start to allocate the swc/swf packaging support into memory.
I decided something else in the project (which is huge) was configuring flexmojo for flex4 (i was trying to build an old flex3 module) and i was getting this in-memory configured plugin. so, I found another flex3 component that was building correctly and changed my flexmojo version to match that one. It worked. It makes sense that maven would have to keep a in-memory instance of the plugin for every version of that plug-in.
So, try changing your flexmojo version number (I changed from 1.6.1 to 1.5.0)
Thanks
Try this
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.flex.samples</groupId>
<artifactId>spring-flex-testdrive</artifactId>
<version>1.0.3.RELEASE</version>
</parent>
<artifactId>collaboration</artifactId>
<packaging>swf</packaging>
<name>Collaboration Sample</name>
<build>
<finalName>collaboration</finalName>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.6.1</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>wrapper</goal>
</goals>
</execution>
</executions>
<configuration>
<output>${basedir}/../testdrive/src/main/webapp/${project.build.finalName}/${project.build.finalName}.swf</output>
<services>${basedir}/../testdrive/src/main/webapp/WEB-INF/flex/services-config.xml</services>
<contextRoot>/testdrive</contextRoot>
<locales>
<locale>en_US</locale>
</locales>
<targetPlayer>10.0.0</targetPlayer>
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>4.0.0.14159</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>4.0.0.14159</version>
<type>pom</type>
</dependency>
<!-- flexmojos Unit testing support -->
<!--
<dependency> <groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-unittest-support</artifactId>
<version>3.2.0</version> <type>swc</type> <scope>test</scope>
</dependency>
-->
</dependencies>
</project>

JAVA_HOME gets mangled by Maven

I'm retrofitting bunch of existing Java projects with unified Maven build. Since each project is mature and has established Ant based build all I'm using maven-antrun-plugin to execute existing build.xml as follows:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<ant antfile="build.xml" target="compile" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
When I run mvn compile build fails with this message:
[INFO] An Ant BuildException has occured: The following error occurred
while executing this line:
build.xml:175: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Java\jdk1.6.0_13\jre"
What puzzles me is
I have JAVA_HOME=C:\Java\jdk1.6.0_13 as part of my environment setup and when mvn.bat is executed that is exactly value I'm getting, however as you see in the error message it comes up as C:\Java\jdk1.6.0_13\jre
If I run ant compile everything compiles just fine
Does it mean that perhaps maven-antrun-plugin does something like set JAVA_HOME=%JAVA_HOME%\jre? I searched my batch/build files I can't find where that change occurs
Thats the down side of external links in an accepted answer. Codehaus shut down and thus the solution is gone. For reference here's the content behind the link - you basically only need to copy the <dependencies>...</dependencies> block to your antrun plugin...
The maven-antrun-plugin runs ant with JAVA_HOME set to the jre subdirectory of the JDK, even if the JAVA_HOME for the overall run is a JDK.
There is documentation elsewhere about how to create a dependency at the project level for the JDK's tools.jar, but this does not help out antrun, which is a plugin.
The following profile does the job. The '..' in the path hauls up past the 'jre' directory to the lib directory.
<profiles>
<profile>
<id>tools.jar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
I was able to fix this by putting the following property definition in my ant build.xml file:
<property name="build.compiler" value="extJavac"/>