I am using a buildnumber-maven-plugin to generate a sequence number for my jar. I will use it during my CICD process.
I followed all the examples available online. However, I can get the ${buildNumber} to print it, but while packaging the jar, I can't get the number, and I got the ${buildNumber} text. I searched for Maven LifeCycle, and I found I need to add it in the validation before any other plugin. But still, I can't solve the issue.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${group.id}</groupId>
<artifactId>${artifact.id}</artifactId>
<version>${model.version}</version>
<profiles>
<profile>
<id>scala-2.11</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
......
</dependencies>
</profile>
</profiles>
<scm>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/dummy</url>
</scm>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<finalName>${artifact.id}.${model.version}</finalName>
<plugins>
<!-- buildnumber-maven-plugin for automatic increment the version number -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<buildNumberPropertiesFileLocation>${build.number.dir}</buildNumberPropertiesFileLocation>
<revisionOnScmFailure>no.scm.config.in.pom</revisionOnScmFailure>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${build.number.dir}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>current build number is "${buildNumber}"</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- ================== ;-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.source.version}</source>
<target>${java.source.version}</target>
<skipMain>true</skipMain> <!-- skip compile -->
<skip>true</skip> <!-- skip testCompile -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>
src/main/assembly/assembly-jar.xml
</descriptor>
</descriptors>
<finalName>${artifact.id}</finalName>
</configuration>
</execution>
<execution>
<id>bin</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>
src/main/assembly/assembly-bin.xml
</descriptor>
</descriptors>
<finalName>${tar.name}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<properties>
<argLine>-Dfile.encoding=UTF-8 -Dlog4j.skipJansi=false -DmodelLogLevel=${modelLogLevel}</argLine>
<modelLogLevel>DEBUG</modelLogLevel>
<build.number.dir>${project.basedir}/buildNumber.properties</build.number.dir>
<java.source.version>1.8</java.source.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Plugin Versions -->
<maven.compiler.plugin.version>3.6.2</maven.compiler.plugin.version>
<maven.reports.plugin.version>2.9</maven.reports.plugin.version>
<maven.assembly.plugin.version>3.1.0</maven.assembly.plugin.version>
<surefire.plugin.version>2.7</surefire.plugin.version>
<group.id>com.test.model_name</group.id>
<artifact.id>proj_abc</artifact.id>
<build.type>snapshot</build.type>
<major.minor.version>0.1</major.minor.version>
<!-- here I am trying to retrieve the actual number-->
<build.number>${buildNumber}</build.number>
<model.version>${major.minor.version}.${build.number}.${build.type}</model.version>
</properties>
</project>
Note: If I run validate I could found the echo message below which means I can get the number correctly from the properties file. If I run package or run I got ${artifact.id}_source-.0.1.${buildNumber}.snapshot without the number.
main:
[echo] current build number is "90"
I also checked this similar question here & enter link description here and other links but can't figure out the problem.
I think what's happening here is that Maven resolves properties near the beginning of the build process.
<build.number>${buildNumber}</build.number>
<model.version>${major.minor.version}.${build.number}.${build.type}</model.version>
When it resolves build.number, ${buildNumber} does not have a value. So, it leaves the variable name unchanged. And I suspect you'd have the same problem if you modified model.version to this:
<model.version>${major.minor.version}.${buildNumber}.${build.type}</model.version>
for the same reason.
You can try using the build-helper-maven-plugin as described in this answer. However, this still may not work since model.version is used as the value of the project.version, which is resolved quite early as it's part of the GAV coordinates. It's worth a try though.
Related
I want to use a scala dependency in a pure Java project. There is no need to write scala in my project but of course I will have to use classes/etc defined in the scala project that I add as a dependency. Want to do this in a intelliJ maven project.
My pom looks like this:
<?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.xxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>group ID</groupId>
<artifactId>scala dependancy</artifactId>
</dependency>
</dependencies>
</project>
Although I dont see any errors in pom, intellij is unable to import packages defined in the scala library. Essentially it cant find them.
What am I doing wrong here?
You can do so by adding the following dependency to your pom.xml file:
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<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>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag.
You have to set name of class with entry point to program ('main' method) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ScalaRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Take a look at this for more information.
I'm using the git-commit-id-plugin (see https://github.com/ktoso/maven-git-commit-id-plugin). It packages correctly when I'm setting up an annotated tag like e.g. v1.0.0, meaning the target-directory has a jar file named deploy-test-Test-v1.0.0.jar.
The problem is, that the maven install phase creates the following files in my local .m2-directory:
Test-${git.closest.tag.name}
|- deploy-test-Test-${git.closest.tag.name}.jar
|- deploy-test-Test-${git.closest.tag.name}.pom
|- _remote.repositories
I've tested this with the example pom.xml.
What can I do to get the same name (deploy-test-Test-v1.0.0.jar)?
<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.mytest</groupId>
<artifactId>deploy-test</artifactId>
<packaging>jar</packaging>
<version>Test-${git.closest.tag.name}</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>Test-${git.closest.tag.name}</revision>
</properties>
<dependencies/>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<!-- *NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here -->
<phase>package</phase>
</execution>
</executions>
<configuration>
<!-- If you'd like to tell the plugin where your .git directory is, use this setting, otherwise we'll perform a search trying to figure out the right directory. It's better to add it explicitly IMHO. -->
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<dateFormatTimeZone>${user.timezone}</dateFormatTimeZone>
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<format>properties</format>
<skipPoms>true</skipPoms>
<injectAllReactorProjects>false</injectAllReactorProjects>
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo>
<skip>false</skip>
<runOnlyOnce>false</runOnlyOnce>
<useNativeGit>false</useNativeGit>
<abbrevLength>7</abbrevLength>
<commitIdGenerationMode>flat</commitIdGenerationMode>
<gitDescribe>
<skip>false</skip>
<always>false</always>
<abbrev>7</abbrev>
<dirty>-dirty</dirty>
<match>*</match>
<tags>false</tags>
<forceLongFormat>false</forceLongFormat>
</gitDescribe>
<validationProperties>
<validationProperty>
<name>validating project version</name>
<value>${project.version}</value>
<shouldMatchTo>
<![CDATA[^.*(?<!-SNAPSHOT)$]]>
</shouldMatchTo>
</validationProperty>
</validationProperties>
<validationShouldFailIfNoMatch>true</validationShouldFailIfNoMatch>
<evaluateOnCommit>HEAD</evaluateOnCommit>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
To incorporate git-commit-id plugin into the version number for the entire maven build cycle (till deploy)
<properties>
<java.version>1.8</java.version>
<snapshot.string>-SNAPSHOT</snapshot.string>
<!-- Snapshot Version Number -->
<!-- <version.number>${git.commit.time}.${git.commit.id.abbrev}${s`enter code here`napshot.string}</version.number> -->
<!-- Release Version Number -->
<version.number>${git.commit.time}.${git.commit.id.abbrev}</version.number>
<release.repo.key>libs-release-local</release.repo.key>
<snapshot.repo.key>libs-snapshot-local</snapshot.repo.key>
<artifactory.url>http://xxx.xxx.x.xxx:yyyy/artifactory</artifactory.url>
<release.repository.url>${artifactory.url}/${release.repo.key}</release.repository.url>
<snapshot.repository.url>${artifactory.url}/${snapshot.repo.key}</snapshot.repository.url>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dateFormat>yyyyMMdd.HHmmss</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<injectAllReactorProjects>true</injectAllReactorProjects>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>change-version</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>
< ![CDATA[
import org.apache.maven.artifact.versioning.VersionRange; git_revision = '${version.number}'
if (!project.properties['revision'] ? .trim()) {
println 'Change `version` to ' + git_revision
System.properties['revision'] = git_revision
project.properties['revision'] = git_revision
project.properties['project.version'] = git_revision
project.properties['git.build.version'] = git_revision
project.version = git_revision
project.artifact.version = git_revision
project.artifact.versionRange = VersionRange.createFromVersion(git_revision)
}
]] >
</script>
</scripts>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.14</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>release</id>
<name>local-releases</name>
<url>${release.repository.url}</url>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>snapshots</id>
<name>local-snapshots</name>
<url>${snapshot.repository.url}</url>
</snapshotRepository>
</distributionManagement>
Also refer to this to work around the "plugin execution not covered by lifecycle" error in Eclipse/SpringToolSuite
see: How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
I've found a solution that worked fine for me. Just added the gmaven-plugin like in the pom-snippet below and the versions will be adapted to the last git-tag.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>project.artifact.version='${git.closest.tag.name}';</source>
</configuration>
</execution>
</executions>
I've also used groovy-maven-plugin to update project.properties. Without this pom.xml was generated with variables that have not been parsed.
project properties
<properties>
<gitClosestTagName>${git.closest.tag.name}</gitClosestTagName>
<gitClosestTagCommitCount>${git.closest.tag.commit.count}</gitClosestTagCommitCount>
</properties>
build final name atteribute
<finalName>${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}</finalName>
plugin definition
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>update-finalname</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.build.finalName="${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}";
project.properties['gitClosestTagName']=${git.closest.tag.name};
project.properties['gitClosestTagCommitCount']=${git.closest.tag.commit.count};
println("project.build.finalName=${project.build.finalName}");
</source>
</configuration>
</execution>
</executions>
I want to build a maven project which has both java and scala source code.
I have installed scala IDE plugin in eclipse and added the "scala-maven-plugin" in pom.xml but the imports of java classes in the scala files are giving compilation errors.
Which is the best IDE to build such mixed projects?
The project structure is
The 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>org.apache.spark</groupId>
<artifactId>spark-examples_2.11</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag.
You have to set name of class with entry point to program ('main' method) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ScalaRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
It seems from your code structure that your Scala classes depend on Java, not the other way around. Yet in your Maven config, Scala gets compiled first. Change it to compile after Java classes.
The following plugin sequence works in my project:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Its safest to go straight to the page provided by the scala-maven-plugin docs where you can find the current pom definition which supports dependencies in both directions
I have a Maven project which I'm trying to package, but I've noticed that all my Java test classes (but none of my Scala test classes) and generated Avro test classes are ending up in the jar.
Folder structure looks fine:
I also noticed that if I add junit as a dependency with <scope>test</scope>, my tests won't compile as it can't find the junit classes, so it looks like Maven is treating all my code including tests as being part of main.
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>com.me</groupId>
<artifactId>proj</artifactId>
<version>1.0.0</version>
<properties>
<log4j.version>2.8.1</log4j.version>
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/test/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Figured it out.
The issue was with the avro-maven-plugin.
It's configuration had sourceDirectory and outputDirectory, both of which had test source paths.
<configuration>
<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/test/java</outputDirectory>
</configuration>
Apparently these were interfering with the compiler plugin which thought that these directories were main source directories and compiled them along with the rest of the main classes. This also explains why my tests were failing to compile when the junit dependency was given a test scope.
The solution was to use testSourceDirectory and testOutputDirectory instead:
<configuration>
<testSourceDirectory>${project.basedir}/src/test/resources/</testSourceDirectory>
<testOutputDirectory>${project.basedir}/src/test/java</testOutputDirectory>
</configuration>
mvn clean install -Dmaven.test.skip=true -X
Here is my pom.xml file and the error i got when building
Error:
Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project load-xml-to-s3: Error reading assemblies: No assembly descriptors found.
<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.tte.s3.load</groupId>
<artifactId>load-xml-to-s3</artifactId>
<version>1.0</version>
<name>load-xml-to-s3</name>
<build>
<plugins>
<!-- TOBE USED LATER - DO NOT DELETE. - KC <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> <file>target/classes/somefile.txt</file> <replacements>
<replacement> <token>SOME TOKEN</token> <value>SOME VALUE</value> </replacement>
</replacements> </configuration> </plugin> -->
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>com.tte.s3.load.driver.Driver</mainClass>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>assembly</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>distribution.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The descriptors attribute of the maven-assembly-plugin expects a path starting from the base directory of your project. For example, if the file is located inside src/assembly/distribution.xml, this is the path you should specify.
There is also a problem in the phase you bound the plugin to. Phase assembly does not exist, you should use <phase>package</phase> instead.
As a side-node, you are using an old version of the plugin (2.2-beta-5). Consider using the latest version instead, which is 2.6.
Sample configuration:
<plugin>
<!-- no need to specify the groupId, it defaults to "org.apache.maven.plugins" -->
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version> <!-- explicit version is safer for build consistency than implicit -->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- bind the execution to the "package" phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/distribution.xml</descriptor> <!-- use the path to the file starting from base directory -->
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Running Maven with mvn clean install will invoke the plugin correctly in the package phase.