Maven not downloading dependencies - java

I'm trying to get Maven to download dependencies. I'm using the commands I believe you are supposed to use, and this is just pure command line, no IDE involvement, but it still isn't happening.
The problem is also with my own project, but I'll use this one by someone else as an example: https://github.com/stephanrauh/BeyondJava.net-Articles/tree/master/MethodModificationWithASM
I've tried the following commands:
mvn compile
mvn test
mvn package
mvn install
mvn dependency:resolve
and all appear to run correctly, even going so far as to claim to have successfully downloaded dependencies:
[INFO]
[INFO] The following files have been resolved:
[INFO] javassist:javassist:jar:3.12.1.GA:compile
[INFO] org.ow2.asm:asm:jar:5.0.3:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.690 s
[INFO] Finished at: 2020-01-13T16:13:34Z
[INFO] ------------------------------------------------------------------------
but when I try to actually run the compiled program, I get an error:
C:\BeyondJava.net-Articles\MethodModificationWithASM>java -jar target\MethodModificationWithASM-0.0.1-SNAPSHOT.jar
Error: Unable to initialize main class de.beyondjava.demos.bytecode.Main
Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
and the same when I try to run from the .class files instead of the jar. And the error is correct: the asm jar is in fact missing:
C:\BeyondJava.net-Articles\MethodModificationWithASM>dir /s *.jar
Volume in drive C is Windows
Volume Serial Number is 04EE-7EB0
Directory of C:\BeyondJava.net-Articles\MethodModificationWithASM\target
13/01/2020 16:01 8,144 MethodModificationWithASM-0.0.1-SNAPSHOT.jar
1 File(s) 8,144 bytes
Total Files Listed:
1 File(s) 8,144 bytes
0 Dir(s) 164,672,442,368 bytes free
nor has it been squirreled away anywhere else; I searched the entire hard disk.
The pom.xml seems to specify the dependency okay, and Maven seems to be happy that it has done so:
<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>de.beyondjava.demos.bytecode</groupId>
<artifactId>MethodModificationWithASM</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MethodModificationWithASM</name>
<description>This demo shows how to create and run byte code in a Java program.
</description>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
So what am I missing?

You cannot just run a jar on the command line without a proper classpath. Maven downloads the artifacts to .m2/repository in your home directory and uses them for the build, but it does not copy them to target or add them to the produced jar.
Most jars are used as libraries and for them, the behaviour is just fine. If you want to run a jar from the command line, it is better to create a jar with dependencies:
How can I create an executable JAR with dependencies using Maven?

Related

Cannot generate runnable JAR for very simple Eclipse Maven project

I would like to generate a runnable JAR for my Eclipse Java projects. The JAR should contain all my code, with unmodified namespaces, classes, resources etc.
My workspace is organized into a multitude of different projects.
When I right-click a project node in Project Explorer, and select "Run As > Maven install", I get the following:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< foo.Project1:foo.Project1 >----------------------
[INFO] Building foo.Project1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for foo.Project2:foo.Project2:jar:0.0.1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.220 s
[INFO] Finished at: 2020-06-26T12:20:11+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project foo.Project1: Could not resolve dependencies for project foo.Project1:foo.Project1:jar:0.0.1-SNAPSHOT: Could not find artifact foo.Project2:foo.Project2:jar:0.0.1-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
foo.Project1 runs fine under Eclipse. Its pom.xml file is:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.Project1</groupId>
<artifactId>foo.Project1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>foo.Project2</groupId>
<artifactId>foo.Project2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
(A ZIP of the two projects can be accessed here: https://wetransfer.com/downloads/b9bb4aa840daa6e7b2dd2c793acdb56420200626103047/32c0fd)
I tried the first solution suggested in How can I create an executable JAR with dependencies using Maven? (with 2300+ score) by:
1: adding the following in the build section of the pom.xml:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>foo.Project1.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
2: right-clicking the project node, then "Run As > Maven build..."
3: defining "Goals" as: clean compile assembly:single, and hitting Run
Same errors.
What am I doing wrong?
If you want to use foo.Project2 as dependency, you need to build it first with clean install.
You always need to build a project before you can use it as dependency in the Maven build.
Eclipse cheats a bit by also allowing you to reference projects from the workspace and therefore allows you to run the program. But for the "real build", you need to build everything in the right order.

Maven site:deploy error: "Error uploading site: Error performing commands for file transfer: Exit code: 0 - The syntax of the command is incorrect."

I'm attempting to use the site:deploy feature of Maven to deploy a project site to a server on my local network. The server is running Windows Server 2012.
I have successfully set up an Apache Archiva Maven repository on it, and I am able to deploy my projects and pull dependencies to/from it just fine.
When I run mvn site:deploy, I get this:
[INFO] --- maven-site-plugin:3.6:deploy (default-deploy) # piserver ---
[INFO] Pushing C:\Users\Eric\Development\Projects\Java\PiServerJava\target\site
[INFO] >>> to scp://192.168.1.215/inetpub/wwwroot/software/projects/piserver/./
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.631 s
[INFO] Finished at: 2016-11-30T10:11:55-07:00
[INFO] Final Memory: 22M/219M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-
plugin:3.6:deploy (default-deploy) on project piserver: Error uploading
site: Error performing commands for file transfer: Exit code: 0 - The syntax
of the command is incorrect.
My POM <distributionManagement> section looks like this:
<distributionManagement>
<site>
<id>etv-site</id>
<url>scp://192.168.1.215/inetpub/wwwroot/software/projects/piserver/</url>
</site>
</distributionManagement>
and my settings.xml <server> section looks like this:
<server>
<id>etv-site</id>
<username>********</username>
<password>********</password>
</server>
For my wagon provider, I use
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</dependency>
</dependencies>
</plugin>
No matter what I try for a url in <distributionManagement>, I get the same error. I've tried
scp://192.168.1.215/inetpub/wwwroot/software/projects/piserver/
scp://192.168.1.215/C:/inetpub/wwwroot/software/projects/piserver/
scp://192.168.1.215/software/projects/piserver/
among others.
Other things I've tried:
URL: scp:http://192.168.1.215/inetpub/wwwroot/software/projects/piserver/; Error: Cannot connect. Reason: java.net.UnknownHostException.
URL: sftp://192.168.1.215/inetpub/wwwroot/software/projects/piserver/; Error: Error uploading site: Exit code: 0 - 'chmod' is not recognized as an internal or external command,
[ERROR] operable program or batch file.
For reference, my Archiva repository URLs look like this:
<repository>
<id>etv-internal</id>
<url>http://192.168.1.215:8080/repository/internal</url>
</repository>
<snapshotRepository>
<id>etv-snapshots</id>
<url>http://192.168.1.215:8080/repository/snapshots</url>
</snapshotRepository>
UPDATE:
The sftp:// solution successfully deploys my site, but I still get the chmod error. I would still like to use scp instead of sftp, though.
Undeleting the answer and keeping the state of what was edited in the question. You shall execute the command
mvn site:deploy
to deploy the package using site-plugin
In order to set the chmod to false for the site deployment you can use the following configurations :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<chmod>false</chmod>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</dependency>
</dependencies>
</plugin>
This would not require changing the execution phase for your plugin either.

How do I run a command line program using m2e (Eclipse/Maven) in the test scope, with test dependencies?

I am having trouble running a java application (static void main) with the m2e plugin. I have created a multi-module project through the ordinary eclipse wizard. It seems as if code in the test directory of one module cannot reference code in the test directory of another module at runtime (compiling works just fine).
Version information
Eclipse = Luna, Build 4.4.0, Build id 20140612-0600
m2e = 1.5.0.20140606-0033
I have created an extremely simple (and contrived) example to demonstrate my problem. Please go easy on me for the pointlessness of this code. Also, forgive me for the verbosity here. Sadly maven questions almost require it.
Here is the project directory structure:
--Project Explorer
|--animals/
|--src/test/java/
|--com.example.problem.animals
|--Animal.java
|--JRE System Library [JavaSE-1.8]
|--src/
|--target/
|--pom.xml
|--dogs/
|--src/test/java/
|--com.example.problem.animals
|--Beagle.java
|--JRE System Library [JavaSE-1.8]
|--Maven Dependencies
|--animals/
|--src/
|--target/
|--pom.xml
|--parent/
|--animals/
|--dogs/
|--src/
|--pom.xml
The parent module pom.xml:
<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.example.problem</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent</name>
<description>Parent module for example project.</description>
<modules>
<module>animals</module>
<module>dogs</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The animals module pom.xml:
<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>
<parent>
<groupId>com.example.problem</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>animals</artifactId>
<name>Animals</name>
<description>Module to hold common animal code.</description>
</project>
The dogs module pom.xml:
<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>
<parent>
<groupId>com.example.problem</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>dogs</artifactId>
<name>Dogs</name>
<description>Module to hold dog specific code.</description>
<dependencies>
<dependency>
<groupId>com.example.problem</groupId>
<artifactId>animals</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
The idea here is to have the Beagle object annotated with #Animal. The annotation lives under the test directory of "animals", while our java runnable class Beagle lives under the test directory of "dogs".
Animal.java:
package com.example.problem.animals;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Simple annotation to denote an animal.
*
* #author Rich - created 03/Sep/2014
*/
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.TYPE)
public #interface Animal {
String noise();
}
Beagle.java:
package com.example.problem.animals;
/*
* Runnable java class that simply prints the animal noise for Beagle to the console.
*
* #author Rich - created 03/Sep/2014
*/
#Animal(noise = "Woof!")
public class Beagle {
public static void main(String[] args) {
Animal animal = Beagle.class.getAnnotation(Animal.class);
System.out.println(animal.noise());
}
}
In order to run the Beagle class, I have created a new run configuration using the eclipse wizard. The configuration type is "Maven Build". The "JRE" tab has the "Runtime JRE" set to be "Workspace default JRE (jre1.8.0_20)". The following settings are made on the "Main" tab of the configuration:
"Base directory" field is set to "${workspace_loc:/dogs}"
"Goals" field is set to "exec:java"
"Profiles" field is not set
"User settings" field is not set
"Offline", "Update Snapshots", "Debug Output", "Skip Tests", and "Non-recursive" checkboxes are not checked
"Resolve Workspace artifacts" checkbox is checked
Parameters that are added
"exec.mainClass" is set to "com.example.problem.animals.Beagle"
"exec.classpathScope" is set to "test"
"Maven Runtime" is set to "EMBEDDED (3.2.1/1.5.0.20140605-2032)"
Running this configuration ultimately fails and produces the following console output:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dogs 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) # dogs ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/example/problem/animals/Animal
at com.example.problem.animals.Beagle.main(Beagle.java:6)
... 6 more
Caused by: java.lang.ClassNotFoundException: com.example.problem.animals.Animal
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.282 s
[INFO] Finished at: 2014-09-13T18:25:51-08:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project dogs: An exception occured while executing the Java class. null: InvocationTargetException: com/example/problem/animals/Animal: com.example.problem.animals.Animal -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
After running the configuration with "Debug Output" set, I dug through the console and found the following interesting lines:
[DEBUG] Configuring mojo 'org.codehaus.mojo:exec-maven-plugin:1.3.2:java' with basic configurator -->
[DEBUG] (f) arguments = []
[DEBUG] (f) classpathScope = test
[DEBUG] (f) cleanupDaemonThreads = true
[DEBUG] (f) daemonThreadJoinTimeout = 15000
[DEBUG] (f) includePluginDependencies = false
[DEBUG] (f) includeProjectDependencies = true
[DEBUG] (f) keepAlive = false
[DEBUG] (f) killAfter = 1
[DEBUG] (f) localRepository = id: local
...
[DEBUG] Project Dependencies will be included.
[DEBUG] Collected project artifacts [com.example.problem:animals:jar:0.0.1-SNAPSHOT:compile]
[DEBUG] Collected project classpath [C:\Users\cairnsjr13\workspace\parent\dogs\target\test-classes, C:\Users\cairnsjr13\workspace\parent\dogs\target\classes]
[DEBUG] Adding to classpath : file:/C:/Users/cairnsjr13/workspace/parent/dogs/target/test-classes/
[DEBUG] Adding to classpath : file:/C:/Users/cairnsjr13/workspace/parent/dogs/target/classes/
[DEBUG] Adding project dependency artifact: animals to classpath
The reason I am so confused is the fact that it looks like it is trying to include the "animals" dependency. I suspect its including the main dependency and not the test dependency. So... after this extremely long winded info dump... Does anyone have any idea how to get eclipse (m2e) to execute this situation? I have gotten it configured properly to handle the test-test compile dependency, but cannot for the life of me get the runtime dependency to work.
Setting exec.classpathScope to test adds the test classes of the executed module to the classpath but not the test classes of the dependency. As shown in the debug output, it adds the test classes of the dogs module but does not add the test classes of animals:
[DEBUG] Adding to classpath : file:/C:/Users/cairnsjr13/workspace/parent/dogs/target/test-classes/
In order to depend on the test classes of animals, you would need to configure a maven-jar-plugin for it by specifying the test-jar goal as explained in this link.
animals
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then update the dependency of dogs on animals to have a test scope as follows:
dogs
<dependencies>
<dependency>
<groupId>com.example.problem</groupId>
<artifactId>animals</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
After adding this configuration, install the animals module into your local Maven repository. This would create a Jar in your local repo that contains the test classes of the module, specifically the Animal class, along with the normal Jar that's created for the main classes. You can either do the install from the command line or right-clicking on the animals project, and selecting Run As -> Maven install.
Then launch the same run configuration in Eclipse but with the "Resolve Workspace artifacts" checkbox unchecked so that the test artifacts are resolved from the local Maven repository.
The weird thing I noticed, when reproducing your scenario, is that if I add all of the above Maven configuration (the maven-jar-plugin and the test-scoped dependency) but I keep the "Resolve Workspace artifacts" checkbox ticked, m2eclipse fails to resolve the test Jar in the workspace even if the target folder contains the Jar and the project is refreshed/updated. I have a feeling that it's a bug in the plugin itself, specifically when resolving a workspace test Jar dependency configured using the test-jar goal.
After a ton of incremental changes and trial-and-error, I've figured out how to get this to work. The nice thing about this approach is that you can still actively develop in the animals project without having to export it as a test-jar everytime. The <dependency> tag has a type attribute which must be set. The dogs pom.xml file then becomes:
<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>
<parent>
<groupId>com.example.problem</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>dogs</artifactId>
<name>Dogs</name>
<description>Module to hold dog specific code.</description>
<dependencies>
<dependency>
<groupId>com.example.problem</groupId>
<artifactId>animals</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
Executing the original run configuration yields the following output:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dogs 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) # dogs ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
Woof!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.310 s
[INFO] Finished at: 2014-09-21T13:53:21-08:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
There are a couple of things to note here.
The scope attribute is not required to be set to test to get this to run. Adding the <scope>test</scope> tag to the dependency will cause the dependency to be omitted in a non-test scope. Since we are running in test scope it does not matter.
This approach will NOT include a dependency on the main code from animals. In the example in the original question, this did not matter because there was no main code source directory. In the event that the test code in animals depends on main code in animals you must add an additional dependency in dogs to pick that up. Here is what the dogs pom.xml file would look like in that situation:
<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>
<parent>
<groupId>com.example.problem</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>dogs</artifactId>
<name>Dogs</name>
<description>Module to hold dog specific code.</description>
<dependencies>
<!-- Including both dependencies for jar and test-jar to get main src included. -->
<dependency>
<groupId>com.example.problem</groupId>
<artifactId>animals</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.example.problem</groupId>
<artifactId>animals</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
</dependencies>
</project>

FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration

I'm trying to start using flyway with maven integration but can't make it work.
I'm following the documentation seems to be very simple so no strange things seem to be done.
My pom.xml is the following:
<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.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<!-- Flyway plugin configuration -->
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<url>jdbc:mysql://localhost:3306/test</url>
<user>test_fede</user>
<password>test_fede</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
<!-- DB dependencies -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I have the directory resources/db/migration/ without any migration yet.
When I issuing flyway:info on cygwin or cmd I got an flyway error:
$ mvn compile flyway:info
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.test:test:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [compile, flyway:info]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [flyway:info {execution: default-cli}]
[INFO] Database: jdbc:mysql://localhost:3306/test (MySQL 5.5)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org.flywaydb.core.api.FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration
Embedded error: Unable to determine URL for classpath location: db/migration (ClassLoader: org.codehaus.classworlds.RealmClassLoader#5bcdbf6)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue May 06 11:06:15 CST 2014
[INFO] Final Memory: 17M/223M
[INFO] ------------------------------------------------------------------------
Can give me a hand on this?
Thans a lot.
This also happens if the compile goal is not executed before calling flyway:migrate. Actually this IS included in the quick start manual. It says:
mvn compile flyway:migrate
However if you miss that detail and start to just call mvn flyway:migrate, the SQL file will not get copied into the target directory (actually the target directory will not even exist) and you get this cryptic error.
Well, just for you to know.
I found the problem, it happens when we setup flyway in our environment but we don't have any migration to be executed.
It shouldn't display a classpath error but fortunately it's working.
By the way, another problem I found is that after executing init if we check with info nothing is displayed. And if we add a new migration with V1 then info won't show it unless we change it to V1_1
Hope to help
I had a similar problem and it was because when I created the migration directory I gave it the name db.migration directly.
By creating the directory db and then inside it the migration directory it worked.
I ran into the same problem. In my case, I had my migration script in the wrong directory that had caused the issue. I moved the script V1__Create_person_table.sql to the right directory at resources/db/migration/ and it worked!!
I faced the same issue. But when i obeserved the logs keenly i found flywaydb is looking in db/migration folder for the script but my script is in db/migrate. so, after correcting the path from db/migrate to db/migration it works!!.
Here's a dumb mistake I've made where I got this pesky error:
Make sure you set your packaging as jar not pom in your pom.xml. Then mvn install and make sure you have a jar for that project in your M2 folder otherwise you will get this error since the migration file wasn't copied over and found.
I had a similar problem too. in my case i thought i had named the directories correctly after triple checking everything. Turned out that i typed migrations instead of migration. As soon as i fixed this everything was fine.
Just before this i had another issue with the underscore after the version marker (V1) in the migration filename. It needs to be a dunder (double underscore) so its always V1__description.sql .
Seems like none of the flyway issues i encounter are big mess-up's. it's always something small that can be easily fixed. It's just about finding out what the problem is. That's the hard part.

Maven android compiling multiple source directories

I have created a maven android project using this archetype. I want to integrate mirah source files inside my project. So I added the plugin mentioned here to my pom.xml. I setup the configuration section for the plugin to point the source directory to src/main/mirah.
But when I run mvn compile it only compiles the sources inside src/main/java. I have tried running it with mvn -X compile to try and debug the issue, but I can't find anything related to mirah or the mirah-maven-plugin there.
Using the archetype it created two projects - project and project-it (tests) , there is a pom.xml in the root directory as well as a pom.xml in project and project-it directories. I have tried the above configurations in both the root directory as well as in project's pom.xml.
I have come across this question related to using the build-helper plugin but I don't know if it will help in my case. Since my mirah plugin isn't getting called at all.
Is this the right way to do what I'm trying to do? Any help on the setup, or pointer to how to troubleshoot this would be much appreciated.
The relevant bit of my pom.xml
<plugin>
<groupId>org.mirah.maven</groupId>
<artifactId>maven-mirah-plugin</artifactId>
<version>1.0</version>
<configuration>
<sourceDirectory>src/main/mirah</sourceDirectory>
<outputDirectory>target/classes</outputDirectory>
<bytecode>true</bytecode>
<verbose>false</verbose>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals><goal>compile</goal></goals>
</execution>
</executions>
</plugin>
Edited as per answer below.
I have added the source directory using the build-helper plugin and I'm able to get the mirah sources to compile using mvn org.mirah.maven:maven-mirah-plugin:1.0:compile from the answer below. But mvn compile still only compiles the sources in src/main/java and not src/main/mirah.
For anyone interested in the output of mvn -X compile here is the pastie.
This page https://github.com/calavera/maven-mirah-plugin#readme says that the mirah plugin extends the default compiler plugin. So this would suggest that the build helper plugin would work for multiple source directories, if it works for the default compiler plugin.
Looking at the mirah plugin, you probably don't need to specify sourceDirectory and outputDirectory yourself, as it seems you're using the defaults.
The -X switch won't have any impact on the mirah plugin directly, as it doesn't do any tracing itself (above what the default compiler plugin does).
Can you show your -X output anyway to show that the mirah plugin isn't invoked?
Alternatively, you could build the mirah plugin yourself and add tracing. It doesn't seem a complicated plugin.
What happens when you try and invoke the plugin directly? E.g.
mvn org.mirah.maven:maven-mirah-plugin:1.0:compile
EDIT:
Tried it myself and this works for me (by 'works' I mean the plugin gets invoked - my build actually fails).
<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>temp</groupId>
<artifactId>temp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.mirah.maven</groupId>
<artifactId>maven-mirah-plugin</artifactId>
<version>1.0</version>
<configuration>
<bytecode>true</bytecode>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With this output:
D:\dev\workspaces\3.6\temp>mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - temp:temp:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [mirah:compile {execution: default}]
[INFO] No sources to compile
Parsing...
D:\dev\workspaces\3.6\temp\src\main\mirah/test.mirah
Inferring types...
* [Mirah::Typer] Learned local type under #<Mirah::AST::StaticScope:0xbc5245> : a = Type(int)
... ETC ...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unknown error - Unknown Error (20047) - D:\dev\workspaces\3.6\temp\target\classes\D:
I don't know what the error means as I'm not a mirah user.

Categories

Resources