Maven does not compile classes - scala

I'm struggling to make maven to compile classes and put them to the jar. Searching through the internet I found, that it expects standard structure (like src/java), but it can be overridden by adding
<packaging>jar</packaging>
<build>
<sourceDirectory>correct_path_to_source_files</sourceDirectory>
</build>
to pom.xml, but it doesn't help, maven keeps ignoring source files without any error: runnning compile says [INFO] Nothing to compile - all classes are up to date. However, no classes appear in target/classes and in jar as well. Other than packaging and build above, pom file contains only dependencies.
I'm not a big expert of java/scala, so I have no idea, what does this thing expect from me. Manual build in Idea solves the problem, but shouldn't it be done by assembly system?
How to make maven compile source files?

Related

Liquibase resource found in both Maven target and Maven repository

I have Eclipse Maven GWT project and I added flowable-form-engine dependency that uses Liquibase. Liquibase is searching for changelog file org/flowable/form/db/liquibase/flowable-form-db-changelog.xml but finds two!
org.flowable.common.engine.api.FlowableException: Error initialising form data schema
at org.flowable.form.engine.impl.db.FormDbSchemaManager.initSchema(FormDbSchemaManager.java:58)
at org.flowable.form.engine.impl.cmd.SchemaOperationsFormEngineBuild.execute(SchemaOperationsFormEngineBuild.java:29)
at org.flowable.form.engine.impl.cmd.SchemaOperationsFormEngineBuild.execute(SchemaOperationsFormEngineBuild.java:24)
at org.flowable.common.engine.impl.interceptor.DefaultCommandInvoker.execute(DefaultCommandInvoker.java:10)
at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53)
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:71)
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
at org.flowable.form.engine.impl.FormEngineImpl.<init>(FormEngineImpl.java:45)
at org.flowable.form.engine.FormEngineConfiguration.buildFormEngine(FormEngineConfiguration.java:172)
at org.flowable.form.engine.configurator.FormEngineConfigurator.initFormEngine(FormEngineConfigurator.java:83)
at org.flowable.form.engine.configurator.FormEngineConfigurator.configure(FormEngineConfigurator.java:63)
at org.flowable.common.engine.impl.AbstractEngineConfiguration.configuratorsAfterInit(AbstractEngineConfiguration.java:859)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:985)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:887)
at sk.dominanz.coarui.server.services.WorkflowServiceAdditional.<clinit>(WorkflowServiceAdditional.java:64)
... 33 more
Caused by: liquibase.exception.ChangeLogParseException: Error Reading Migration File: Found 2 files that match org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:118)
at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:217)
at liquibase.Liquibase.update(Liquibase.java:190)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.Liquibase.update(Liquibase.java:175)
at liquibase.Liquibase.update(Liquibase.java:168)
at org.flowable.form.engine.impl.db.FormDbSchemaManager.initSchema(FormDbSchemaManager.java:52)
... 48 more
Caused by: java.io.IOException: Found 2 files that match org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:206)
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:71)
... 55 more
So I debugged it and it finds one resource from target directory:
jar:file:/C:/work/git/coarui/target/Main-1.0-SNAPSHOT/WEB-INF/lib/flowable-form-engine-6.4.0.jar!/org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
and other resource from maven repository:
jar:file:/C:/Users/Piro/.m2/repository/org/flowable/flowable-form-engine/6.4.0/flowable-form-engine-6.4.0.jar!/org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
Is there a way to ignore one of them, or is my build path or dependency definition wrong?
My build path contains:
src/main/java sources
src/test/java sources
JRE System library
Maven dependencies (in C:/Users/Piro/.m2/repository...)
JUnit4
Looking at source code resources are read classLoader.getResources(path); where class loader is jetty class loader JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.
In my run/debug configuration I have classpath similar to build path plus GWT library gwt-dev-2.8.1.jar - C:\Users\Piro\.m2\repository\com\google\gwt\gwt-dev\2.8.1
In pom.xml dependency is defined as:
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-engine-configurator</artifactId>
<version>${flowableVersion}</version>
</dependency>
Maven GWT plugin groupId=net.ltgt.gwt.maven, artifactId=gwt-maven-plugin has configuration parameter classpathScope but I tested <classpathScope>compile+runtime</classpathScope>, <classpathScope>compile</classpathScope> and <classpathScope>runtime</classpathScope> and the same error occurs.
Searching the internet I found similar posts on flowable forum (1, 2) but no solution is provided.
This generally happens when you mix client and server code in the same Maven module, and given how GWT works there's no (easy) around that, besides splitting your code in separate client and server (and possibly shared) Maven modules.
You can have a look at https://github.com/tbroyer/gwt-maven-archetypes for examples (disclaimer: I'm the author, but also a member of GWT's Steering Committee)
it seems that for some reason your .m2 is in the classpath. If it really makes sense to you then you can try to use <scope>provided</scope> in a pom where you declare dependency to flowable-form-engine-configurator. However you may decide to exclude .m2 from classpath which is better I think.

Depend on test artifact of another project in Ivy (in sbt)

We are having trouble adding a test artifact from one third-party project to the Ivy test conf of another project.
We cannot express the following dependency: myprj-common/test -> framework-app-base/test using Ivy (in an sbt build).
Project framework-app-base has src/main/scala, which generates jars/framework-app-base-0.0.123-SNAPSHOT.jar in the Ivy repo
and src/test/scala, which generates tests/framework-app-base-0.0.123-SNAPSHOT-test.jar
For instance, there is a utility class /framework-app-base/src/test/scala/com/myco/fmwk/framework/base/test/util/TestUtility.scala, which ends up in ${user.home}/.ivy2/repo/com.myco.fmwk.framework/framework-app-base/tests/framework-app-base-0.0.123-SNAPSHOT-test.jar.
Our code from myprj-common/src/test/scala uses class TestUtility, and this works fine in the IDE.
When we try to run the sbt build (sbt clean update compile test), compilation works fine, but tests fail because TestUtility not found.
When we show test:dependency-classpath in sbt, we see that the main artifact is in the classpath, but the test artifact is not:
jars/framework-app-base-0.0.123-SNAPSHOT.jar is in the classpath
tests/framework-app-base-0.0.123-SNAPSHOT-test.jar is not in the classpath
We have tried specifying the dependency as shown below, but it makes no difference:
<dependency org="com.myco.fmwk.framework" name="framework-app-base" rev="0.0.+" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)" />
<dependency org="com.myco.fmwk.framework" name="framework-app-base" rev="0.0.+" m:classifier="test" conf="test->test(*)" />
How can we express this dependency?
Projects myprj-common and framework-app-base are not inside the same multi-project, so myprj-common can only depend upon the JARs generated by framework-app-base. In other words, it is not possible to add a .dependsOn() to the build.sbt (AFAIK).
We ended up converting our dependency specifications to sbt syntax, inside build.sbt. To express the dependency on the test artifact, we use
"com.myco.fmwk.framework" % "framework-app-base" % "0.0.+" % "compile->test;test->test" classifier "" classifier "test"
which means that we add to the classpath framework-app-base-0.0.123-SNAPSHOT AND framework-app-base-0.0.123-SNAPSHOT-test.jar.jar respectively.
Maybe this can be done in a similar way using Ivy files, but we wanted to have all of our build specification expressed in a single format.

how to exclude specific jar if possible from child module itself or war

child module has below dependency so this alfresco-repository-5.1.1-tests.jar is coming that i can see in Maven dependencies in eclipse.I will use this jar only for compiling test classes.
<groupId>org.alfresco</groupId>
<artifactId>alfresco-repository</artifactId>
<version>5.1</version>
<classifier>tests</classifier>
<scope>test</scope>
I have parent module which will generate war which has this child module has dependency.so this jar is coming also in war.
so how to exclude this jar in war?
When you package a Maven project to a WAR file, you don't package any dependencies mentioned within your pom.xml inside your WAR. your WAR file will include your pom.xml and your .class files in it, without dependencies.
If you need that dependency for testing purposes only, the test scope
<scope>test</scope>
is enough. That'll include the requested dependency in your classpath only when running your JUnits or any other tests. You can verify that if you'll execute the test phase & compile phase separately in debugging mode, and make sure that in test phase it's being included in your classpath, and in compile phase, it doesn't. To debug the test phase in command-line:
mvn -X test

Maven add custom multiple jars from folder

I have a custom list of jars around 40 jars in a libs folder. I want to add all as a maven dependenices.
+ project
pom.xml
+ src
+ libs
Is there any way by that add all jar at a time.
Maven manages dependencies rather different than just including jars.
Essentially if you have a dependency on A and A uses B, you will need to have both A+B in your lib folder, but only A in your maven project, because maven transitively will include the subdependencies.
You should probably look through the maven repository, and see if you can find the jar files there in a similar version, and include that instead.
i.e. if you have commons-collections4-4.0.jar, use http://search.maven.org and write commons-collections4, and you will see a list of candidates. probably some with multiple version. Note, maven uses a groupId to scope jar files, so pick one with a suitable groupId, in this case org.apache.commons (Since commons-collections is an apache.org project).
When you have identified your dependency, it will show you ways to include it in your build, e.g. for maven, it would be
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
Looking at the pom file, you will be able to spot potential subdependencies, but otherwise, once you have added the dependency to your <dependencies/> section of your pom, run a mvn dependency:tree or mvn dependency:list to see how dependencies are transitively included.
Should you end up with libraries you cannot find in maven central, read this guide for the rest http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Found one wonderfull plugin to achieve this task. addjars-maven-plugin

How to stop maven-gwt-plugin from copying test scoped dependencies into target lib folder when running gwt:run

When running mvn gwt:run all the test scoped dependencies are copied into the WEB-INF/lib folder.
I have tried using runClasspathExcludes in the gwt-maven-plugin configuration (see sample project pom for example) but it doesn't seem to have any effect.
The dependencies are marked as <scope>test</scope> in the pom and only get copied when running gwt:run (not when building the app).
I found this bug report on the gwt-maven-plugin Jira: gwt:run does not use the 'runtime' scope's classpath. The last comments says:
requiresDependencyResolution set to
"test" to ensure all artifacts are
available as dependencies when
building the classpath.
I think that means it uses the test scope to for the dependency resolution which would explain how the dependencies get there but the question is how to exclude certain dependencies?