I am trying to automate testing for my Android app using Maven and Robolectric. The problem that I have is that I won't be running the tests on my local machine and the Android SDK won't be installed on the machine running the tests. I have used the maven-dependency-plugin to grab the sdk from our repository and unpacked it in the process resources phase, the problem is that this occurs after the need to access the files. When I try to use the apk packaging it never gets to the SDK download because it can't find the SDK. So my question is this: Is it possible to trigger this download before anything else happens in the build? If anybody has any light to shed on how to properly install the sdk at build time it would be much appreciated. Let me know if I can add any additional information.
Both Robolectric and maven-android-plugin both need SDK. Android plug-in requires build tools/adb while Robolectric needs the corresponding android.jar.
So, you'll have to create maven tasks/goals for:
Download SDK zip from some url.
Unpack the zip on test machine, in a directory.
update the android.sdk.path property of POM, to point to sdk directory.
Some snippets I found, might help:
Download:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>download-android-sdk</id>
<phase>pre-integration-test</phase>
<goals>
<goal>download-single</goal>
</goals>
<configuration>
<url>http://dowloadsite.com/<url>
<fromFile>/downloads/sdk.zip</fromFile>
<toDir>${project.build.directory}/sdk</toDir>
</configuration>
</execution>
</executions>
</plugin>
Unpack:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>unpack-sdk</id>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<unzip src="${project.build.directory}/sdk/sdk.zip" dest="${project.build.directory}/sdk/" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Related
There are two different javafx applications using javafx-maven-plugin to generate native windows installer. In both applications the installers are generated and can be seen at target\jfx\native .
When the first app installer setup installation process is started, setup shows files are copied in C:\Users\Yunus\AppData\Local\CooperativeERP.
The problem is when the second application installation process is started it goes to the same folder and updates some files which makes first app installed unusable.
Plugin Maven XML is as follows:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.6.0</version>
<configuration>
<mainClass>re.iprocu.coperativeerp.MainApp</mainClass>
<bundleArguments>
<licenseFile>termsOfService.rtf</licenseFile>
</bundleArguments>
<additionalAppResources>src/main/additionalAppResources</additionalAppResources><!-- name does not matter, it's just some folder :D -->
<!-- DO SHOW DEBUG-OUTPUT -->
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- required before build-native -->
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
<execution>
<id>create-native</id>
<phase>package</phase>
<goals>
<goal>build-native</goal>
</goals>
</execution>
</executions>
</plugin>
What should i do to make the two setup install as different application and not to get to each others way.
Found out that zen java maven plugin uses a Main class package as unique identifier for application, and in this particular case both application had the same package name.
Changing package for one application solved my problem.
i was faced with a problem, during deploying Java based app with Angular 2 fronend.
My app needs to be installed with NodeJs and it's "npm install" to fetch all it's dependencies from package.json.
And only than with maven.
Angular2 app is located in java webapp folder.
I saw buildpacks to install it. But they dont work. For example
this one
https://github.com/Vincit/heroku-buildpack-java-nodejs
It searches for *.ts files in the root, but not in the "webapp" java folder.
Is there some smart buildpacks for task like that, or others convinient ways to do it simply?
Thank you in advance!
You can do this with Heroku's support for multiple buildpacks on an app. In short, run:
$ heroku buildpacks:clear
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/java
In your case, the situation is probably very similar to this JHipster example, which uses Node.js and angular. There are a few things to consider:
The Heroku Node.js buildpack will not install devDependencies by default. You either need to move them to dependencies or set the config var NPM_CONFIG_PRODUCTION=false.
If you don't need your node_modules directory or Node.js runtime at runtime, it will make your app huge. You can use Maven to remove them.
Here's an example:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>clean-build-artifacts</id>
<phase>install</phase>
<goals><goal>clean</goal></goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>node_modules</directory>
</fileset>
<fileset>
<directory>.heroku/node</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
This is described in more detail in the JHipster post.
I use this plugin:
https://github.com/eirslett/frontend-maven-plugin
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v4.4.3</nodeVersion>
<npmVersion>3.8.3</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>--strict-ssl=false install</arguments>
</configuration>
</execution>
<execution>
<id>npm build prod</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build.prod</arguments>
</configuration>
</execution>
</executions>
</plugin>
npm build.prod is my gulp task to build for prod deployment and is specified as a script in my package.json (I'm using the angular 2 seed): https://github.com/mgechev/angular-seed
I had to create a task to copy to a place for my java app to use the files statically:
import * as gulp from 'gulp';
let gnf = require('gulp-npm-files');
let resourceDest = 'src/main/resources/public';
export = () => {
gulp.src('**', {cwd:'./dist/prod'}).pipe(gulp.dest(resourceDest));
gulp.src(gnf(), {base:'./'}).pipe(gulp.dest(resourceDest));
};
This copies my compiled angular 2 javascript into src/main/resources/public
I am trying to import a java+Scala project into Eclipse(v4.6.1 Neon). This consist a parent project with scala-maven plugin configured as follows:
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
While importing the project it show an error:
No marketplace entries found to handle scala-maven-plugin:3.2.1:add-source in Eclipse. Please see Help for more information.
While imported to eclipse, there is no source folder created in eclipse for scala(like for java src/main/java and src/main/resources). Also in child projects, it shows this Error.
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.2.2:add-source (execution: scala-compile-first, phase: process-resources).
Although I am able to build the project from command line.
I also have tried installing Scala IDE Plugin for eclipse, but nothing worked. I dont't want to mark this goal as ignored.
The goal add-source, should be used with "mvn eclipse".
But you seem to use m2e/m2eclipse, in this case did you install https://github.com/sonatype/m2eclipse-scala. this plugin setup your eclipse project to use scala + setup of scala folder.
From my personal experience, it's easier to mixe .java and .scala into the same source folder. Easier for IDE, build tools and dev (less directories to navigate into).
Hey PyThon read my answer here . It has the exact pom.xml that you need. It works great.
I have a jar plugin but it's not running because it isn't including the external dependencies in the jar. I can't seem to figure out how to include these dependencies, I seem to be finding a bunch of different solutions that conflict with each other for some reason. I ideally would like it to run on systems without the need for any special maven commands.
create maven pom.xml with
<packaging>jar</packaging>
By default it should not pack into your jar all dependent libraries.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
What you are looking for is to build an über-jar. The Maven Shade plugin can do that - http://maven.apache.org/plugins/maven-shade-plugin/. It even allows for renaming of classes.
I have been trying for the last hour or so to get my Maven project to include source files from its dependencies, but for some reason, it isn't. I have followed the steps provided by the following link, but when I compile and run the plugin, I get a ClassNotFoundException:
https://github.com/mkremins/fanciful
I have made sure to include the dependencies and the repository from the link above into my pom.xml file, but when I compile, they don't get added to my .jar file.
I am fairly new to using Maven, and like it so far, albeit that it can be a pain to solve issues like this.
I am building the project by doing the following:
Right click project -> Run As -> Maven Build -> Goal: clean install
EDIT -
With a little more searching around, I figured it wasn't as easy as I thought so. I added the following to my pom.xml build section:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>mkremins:fanciful</include>
<include>org.json:json</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
The only problem with this is that I needed to also manually include the dependencies of the main library I wanted to use - mkremins:fanciful; is there flag or option to automatically copy dependencies from the one file I need, rather than also including <include>org.json:json</include>?
Well, if you want to have your dependencies copied to your target jar, you need to tell maven to do so! Maven doesn't know if the artifact of your project is meant to be self-sufficient executable jar, jar to be executed inside a container or just a dependency or library for another project.
You might want to use copy-dependencies task from maven-dependency-plugin
For example:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}</outputDirectory>
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For more tweaking you might also want to play with jar plugin and assembly plugin. On more about creating executable jars:
http://www.ibm.com/developerworks/java/library/j-5things13/index.html?ca=dat-
You have mistaken the idea of Maven. Maven is intended to use dependencies which are located in Maven Central. It's idea is not to compile dependencies. I recommend you to read about Maven and learn how it works.