Maven scope in plugin' dependencies - maven-3

I am using Maven 3.x (3.2.5) and my project use the maven-antrun-plugin with additional dependencies. While I understand the principle behind, I have trouble understanding the use of <scope /> in this case:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<!-- executions -->
<dependencies>
...
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
</plugin>
I am depending upon mysql-connector-java with a runtime scope, whereas other dependencies use default (compile) scope.
The maven-antrun-plugin is used to do something to various database (hence the dependency). However, since the project is not tied to a specific JDBC Driver, the driver is not added to the project dependencies. The Ant task runs with several driver as dependencies since it may use such database depending on the configuration (eg: one could use jdbc:mysql, other jdbc:oracle:thin, etc...).
To my understanding, since the plugin executes, maven ignore the scope.
Is that true ?
Note: I've read the Maven documentation, and this point is not discussed. I'm pretty sure it is ignored but I'd like insight before.

Related

Vaadin: Reduce package.json to the only used dependencies in production mode

We're using in our project BlackDuck from Synopsis to identify the licenses of our used dependencies. There is actualy an small issue with Vaadin: When we build the frontend - based on Vaadin Core - in production mode the package.json is stuffed with a lot more dependencies than we use. And it includes also features from the pro-version. Since the detect-script for BlackDuck scans this package.json we get a lot of "false-positives". So is there a way of reducing the package.json to the only required dependencies by creating the build via Vaadin? As far as i could see the package.json will be always overwritten, when starting the build. Of course i can "hack" the package.json afterwards with a script, but this is not the way i look for.
Here is our profile for creating the "production ready" frontend sources:
<profile>
<id>production-mode</id>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-frontend</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<productionMode>true</productionMode>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Thanks for your help in advance!
Update: This response was based on speculation rather than how things actually work.
The dependencies that Vaadin generates into package.json are based on the Java dependencies that are defined through Maven or Gradle.
If you want to have all the free components but want to avoid the commercial ones, then you can just change the com.vaadin:vaadin dependency to com.vaadin:vaadin-core. If you want to be even more granular, then you can either exclude the ones you don't want or build your own platform by including only the things you think you need out of the dependencies listed in https://mvnrepository.com/artifact/com.vaadin/vaadin-core/23.0.8.

Grails: add a build task for compilation

I'm using grails 2.4.4.
Some of my classes are annotated and a APT (annotation processing tool) has to process these annotations during compilation to generate some sources.
I was able to get everything done with the workaround of creating a maven pom.xml by running grails generate-pom and from there add specific plugins and configure them.
Is there a possibility to use the built-in grails compiler config BuildConfig.groovy to reach the same goal without the detour via maven pom.xml?
To be more specific, I'm creating a workflow with AWS SWF. And SWF uses annotations that should generate some client classes. Therefor in the pom.xml I added this. It works perfectly when I run mvn compile:
<build>
...
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>src/generated</outputDirectory>
<processor>com.amazonaws.eclipse.simpleworkflow.asynchrony.annotationprocessor.AsynchronyDeciderAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-flow-build-tools</artifactId>
<version>1.9.34</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.21</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
</plugin>
...
</build>
I found out my self how to to it within grails.
Basically I created a script that you can call with the grails command. This script is nothing else but a gant script with which you can interfere with ant. Plus I had to add libraries to the libs folder in grails in order to have them in the classpath.
These are the steps:
Create a new grails script
grails create-script generateSources This will create a script called GenerateSources.groovy into your grails scripts directory
Edit the GenerateSources.groovy file
includeTargets << grailsScript("_GrailsCompile")
target(generateSources: "Generates sources for SWF workflow") {
ant.delete(dir:"src/generated/java")
ant.delete(dir:"target/generated-classes")
depends(compile)
ant.mkdir(dir:"src/generated/java")
ant.mkdir(dir:"target/generated-classes")
ant.javac(destdir:"target/generated-classes", classpathref:"grails.compile.classpath", source:"1.7", target:"1.7"){
compilerarg(value:"-proc:only")
compilerarg(value:"-s")
compilerarg(value:"src/generated/java")
src(path:"src/java")
}
}
setDefaultTarget(generateSources)
This includes references and tasks from the GrailsCompile script, deletes some folders (in case you re-run this script), calls the compile task from the native grails gant, creates the necessary target folders
Copy the necessary jars to the grails lib folder. In my case I had to copy the aws-java-sdk-flow-build-tools-1.9.34.jar which includes the Annotation processor and another dependence freemarker-2.3.18.jar. Javac will automatically call the correct APT in order to process the annotations in the the folder src/java
Run the script
grails generateSources which will run the compile task and your new task
Open:
I'd like to hook up this task automatically when grails compile is called. I'm still working on that thoug.

Parent POM is taking the same version which I am giving in the module version

I have a multi module maven project for e.g.
A
B
C
D
E
Currently this project is working fine and have a single job to build all the modules and upload to the artifactory with some version for e.g. 4.0.0-.They are using versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} from Jenkins job.Now my next task is to split this project into module so they dev team can build each module independetly but my issue is some modules is having the dependecy on other modules for e.g
Module B is having dependecy on module A and Module C.if I build the module A first then it generate the number 4.0.0-00001 and upload it to the artifactory and then I build the module C then it generate the build 4.0.0-00005.Now the question comes how could I build the module B which is having the dependency on module A and C.In my opinion I need to define the version of module A and C explicitly in the dependency section.
<dependency>
<groupId>com.xyz.engine</groupId>
<artifactId>A</artifactId>
<version>4.0.0-00005</version>
</dependency>
From my module POM I am calling my parent POM and In jenkins job I am giving
versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} for versioning purpose if I explicity define the version of A module then it is also passing the same value to the Parent POM and searching for it which is not avilable.Below is my module POM file
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.truvenhealth.analyticsengine</groupId>
<artifactId>AnalyticsEngine</artifactId>
<version>4.0.0-00002</version>
</parent>
<artifactId>LicenseVerifier</artifactId>
<name>LicenseVerifier</name>
<packaging>jar</packaging>
<dependencies>
<!-- Modules dependencies -->
<dependency>
<groupId>com.xyz.engine</groupId>
<artifactId>Common</artifactId>
<version>4.0.0-00007</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<!-- External dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.verhas</groupId>
<artifactId>license3j</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- Plugin configurations inherited from the parent POM -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
it is taking the same value for Parent POM which I assigned to Common module .I am keeping the Parent POM in separate repository it should not take the same value it should only take that value which I am defining for the Parent POM and it should download it from their and provide all the values to module POM and the build should be created for module LicenseVerifier with different version.
If you have a multi module build which looks like this:
root (pom.xml parent of all modules)
+---- module-a (pom.xml)
+---- module-b (pom.xml)
+---- module-c (pom.xml)
+---- module-d (pom.xml)
To build a module separately you can do this via Maven like this:
mvn -pl module-a clean package
This will build the module-a only and get the dependencies of other modules from the remote repository. Or you can enhance that like this:
mvn -pl module-a -amd clean package
where the option -amd means --also-make-dependents. If a developer needs a particular state you can do this by a mvn install first and afterwards only build the module you would like to build.
A very important thing in relationship with multi module builds is to have the same version for all modules and the parent. So dependencies between those modules is no problem.
Starting with Maven 3.2.1 you can define the version via properties.
A simple change to prevent Maven from emitting warnings about versions
with property expressions. Allowed property expressions in versions
include ${revision}, ${changelist}, and ${sha1}. These properties can
be set externally, but eventually a mechanism will be created in Maven
where these properties can be injected in a standard way. For example
you may want to glean the current Git revision and inject that value
into ${sha1}. This is by no means a complete solution for continuous
delivery but is a step in the right direction.
Furthermore during development i would prefer the SNAPSHOT versions which the cleanup in the repository manager simpler. So in essence i don't any need to separate the modules which logicaly belong together.
Apart from that if you use the same version within your multimodule build you can use things like this: ${project.version} to define the version of a dependency which is part of the reactor.

spring boot adding Manifest entry key respresenting build version in maven pom.xml

What I would like to do is be able to put the version of my build into the maven command line and have that build version arrive in the MANIFEST.MF file. I was hoping to use the spring-boot-maven-plugin to do so.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--put something here from the command line? -->
</configuration>
</plugin>
I'm sorry that I haven't got a broken example for you to troubleshoot, but I can't seem to find any documentation on this the plugin usage examples that I have found don't cover anything like this.

Wrap a bunch of ant tasks in a maven plugin?

I have a bunch of maven projects that needs to execute the same sequence of ant tasks using the maven-antrun-plugin during the build/deploy phase.
I don't want to override the implementation of maven-antrun-plugin in a parent project so all other projects using this plugin will inherit these steps.
I was therefore looking into writing my own maven plugin that works as a maven-antrun-plugin wrapper with a special sequence of ant tasks. But currently I have had no success doing this.
I have looked at:
http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html
but run into the same problem described here:
http://www.mail-archive.com/users#maven.apache.org/msg92676.html
(using the versions suggested in the above post does not solve the problem)
and from :
http://www.mail-archive.com/users#maven.apache.org/msg115264.html
it looks like the tutorial only works with maven2:
I have also tried to steal something from here:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
but still no working plugin.
The plugin that I want to wrap looks like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- execute task A,B and D -->
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Is it possible to put the sequence of task A, B and C out in another plugin an then use that plugin where ever needed?
I have also tried to move the antrun plugin to a parent and the disable it for some of the children setting inheritance to false:
http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_inherited_Tag_In_Build_Plugins
but the task defined in the parent is still executed so setting the inheritance to false does not seem to work.
If you want to define a <plugin> in the parent and allow children to use it as appropriate, then you can define it within a <pluginManagement> section. By doing this, the parent will not execute the plugin. It will execute only for those children which define this plugin in their pom.
As for sequencing of ant tasks, would it not be simpler to create a task in your ant script, which calls the tasks A, B and C in sequence and continue to use the default maven-antrun-plugin functionality?

Resources