Integrate create-react-app into maven build process - maven

I am trying to integrate a recently created ReactJs application into the build process of the rest of my larger maven based application. I have done this in the past for an AngularJs application using npm, Gulp, and Bower. The difference this time around is that I am using Yarn but also the create-react-app base application from Facebook which relies on the 'react-scripts' development dependencies.
Previously my pom.xml for the maven project that built the AngularJs app looked as 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>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<name>MyApp Service</name>
<description>MyApp Service</description>
<parent>
...
</parent>
<profiles>
<profile>
<id>exec-unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<npmexec>npm</npmexec>
<gulpexec>gulp</gulpexec>
<bowerexec>bower</bowerexec>
</properties>
</profile>
</profiles>
<properties>
<frontendDir>src/main/myappui</frontendDir>
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<executable>${npmexec}</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${frontendDir}</workingDirectory>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<executable>${bowerexec}</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${frontendDir}</workingDirectory>
</configuration>
</execution>
<execution>
<id>gulp build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<executable>${gulpexec}</executable>
<arguments>
<argument>prepare-for-maven-war</argument>
</arguments>
<workingDirectory>${frontendDir}</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I am not particularly sure what to do about the 'react-scripts' part. I tried adding <yarnexec>yarn</yarnexec> with an execution for yarn install and yarn build but it didn't provide desired results.

Related

Maven: how to exec a pom twice with different profiles?

I want to make a build with Maven within a pom which can be built with two different profiles.
In other words, my task is to force the build in order that the build produces two different builds in the target folder as like I will execute "maven install -P" two times.
So, to be more clear:
one single invocation
two different results based on the profile associated in that time
I've tried the exec-maven-plugin but I'm not sure if is the correct way, because it's not doing what I desire.
How can I perform that?
Here's the pom I'm trying.
The tasks are:
copy resources from another project
replace content based on the profile
Build both profiles.
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>
<artifactId>MavenDoubleInstallation</artifactId>
<profiles>
<profile>
<id>profileA</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>profileA</env>
<token>/path/for/profileA</token>
</properties>
</profile>
<profile>
<id>profileB</id>
<properties>
<env>profileB</env>
<token>/path/for/profileB</token>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/${env}/result</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../SourceProject/resources/result</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}/target/classes/${env}/result</basedir>
<includes>
<include>**/*.sh</include>
</includes>
<replacements>
<replacement>
<token>%%TOKEN%%</token>
<value>${token}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>build-profileA</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>maven</executable>
<arguments>
<argument>-P profileA -X</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>build-profileB</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>maven</executable>
<arguments>
<argument>-P profileB -X</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Removing surefire plugin

I have the following parent POM:
<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>my_group</groupId>
<artifactId>my_artifact</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<modules>
<module>../common-module</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<https.website>http://intosimple.blogspot.com</https.website>
<snapshot.version>0.0.1</snapshot.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And the corresponding child POM is as follows:
<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>My_group1</groupId>
<artifactId>my_artifact_1</artifactId>
<version>0.0.1-</version>
<relativePath>../base/pom.xml</relativePath>
</parent>
<artifactId>some_module</artifactId>
<properties>
<jdk.version>1.8</jdk.version>
<jacoco.version>0.7.5.201505241946</jacoco.version>
</properties>
<dependencies>
<!-- some packages here-->
</dependencies>
<build>
<finalName>my_artifact_1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.0400</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Even though, there is no mention of surefire plugin, the effective POM somehow is getting that. Could it be coming from any dependency?
I doubt that surefire might be causing Jacoco to fail. I want to remove it completely. What is right way of doing it?

deploy zip created by grunt to maven repository

I use the frontend-maven-plugin to run a grunt build with maven.
I have the following pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.a.b</groupId>
<artifactId>kuku</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
<version>0.0.19</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v0.10.33</nodeVersion>
<npmVersion>1.4.28</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- Optional configuration which provides for running any npm command -->
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build-nightly --no-color</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The grunt task creates a zip file which is called kuku.zip. I want to deploy this zip file to a maven repository.
There are questions on deploying zip files to maven:
Jenkins "Post Build Action" to deploy zip on Maven repository
But here the situation is different because there already a jar is created and i want to attach an additional zip file and here i don't have another artifact.
How can i achieve this task with maven?
I followed the approach of maven-assembly-plugin.
First i defined an assembly descriptor.xml
<assembly>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>kuku</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
and here is the changed pom
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a.b</groupId>
<artifactId>kuku</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
<version>0.0.19</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v0.10.33</nodeVersion>
<npmVersion>1.4.28</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- Optional configuration which provides for running any npm command -->
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build-nightly --no-color</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

How to run a LoadFromFile command using pom.xml in MAVEN?

I am working on a tool called Windchill. I have prepared a build to load few attributes through xml files.To load these xml files i use the following command.
For eg: windchill wt.load.LoadFromFile -d C:\ptc\Windchill_10.1\Windchill\loadFiles\pdmlink\itc\attributes\Attributes.xml -u wcadmin -p wcadmin
Like this I have some 100 commands to run manually on the windchill command prompt. So I basically want to automate the process by executing these commands sequentially using MAVEN without any much of manual work.
Is there any way to deploy this build. Please help.
Thanks.
I would suggest to take a look at the exec-maven-plugin which seemed to be the right choice for what you like to achieve.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
...
<phase>WhatEver</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill </executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>and so on</argument>
...
</arguments>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
<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>Build</groupId>
<artifactId>Build_SMB</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>SMB PROJECT</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<!-- optional -->
<workingDirectory>C:/mvn/test</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>-d</argument>
<argument>C:/ptc/Windchill_10.1/Windchill/loadFiles/pdmlink/itc/attributes/Attributes.xml</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>WT_HOME</key>
<value>${env.WT_HOME}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>

How to use master pom file to checkout all modules of a web application and build all modules

I have a web application that relies on several modules. So to build it, I have a master pom.xml file. What I want this pom file to do is to checkout out all the modules.
below is my pom file.
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<!--<developerConnection>scm:svn:svn://svnserver/svn/module1/trunk</developerConnection>!-->
<username>username</username>
<password>password</password>
</configuration>
</execution>
<execution>
<id>check-out-project2</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<username>username</username>
<password>password</password>
</configuration>
</execution>
</executions>
I have tried mvn scm:checkout and mvn scm:checkout -check-out-project1 but it give me the error:
Cannot run checkout command : Can't load the scm provider. You need to define a connectionUrl parameter.
I don't understand why this is happening since I have the connectionUrl parameters defined inside the pom file already,the ideas point that I want to get to is having the pom file configured to be able to checkout multiple projects at the same time. Please let me know what I am doing wrong here, Thanks in Advance.
I found that if placing each of the checkouts into its own <execution> ... </execution> and within place the individual <configuration> ... </configuration> for them works. For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<executions>
<execution>
<id>repo1-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo1.url}</connectionUrl>
<scmVersion>${my.repo1.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo1}-${my.repo1.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
<execution>
<id>repo2-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo2.url}</connectionUrl>
<scmVersion>${my.repo2.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo2}-${my.repo2.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
I faced to same situation and I found a solution -using your code :D- that works on my computer:
<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.xxx.internet</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://www.mySite.de</url>
<scm>
<connection>scm:svn:http://svn-repo-adress:8080/repo/myDirectory</connection>
<developerConnection>http://svn-repo-adress:8080/repo/myDirectory</developerConnection>
<tag>HEAD</tag>
<url>http://svn-repo-adress:8080/repo/myDirectory</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.6</version>
<configuration>
<goals>checkout</goals>
<checkoutDirectory>target/checkout</checkoutDirectory>
<username>username</username>
<password>userpassword</password>
</configuration>
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
After I executed "mvn scm:checkout" on the cmd console it did work.
I think the important point was to add the scm tag first, before I had executed the build tag.

Resources