TeamCity, Maven Build not found child module - maven

I've Maven project with one subproject, when I run my install task on parent project from IDEA (IntelliJ IDEA) all works fine and maven resolve child module.
My projects are versioned on subversion, and this is the filesystem structure:
project
|--pom.xml
|--subproject
|
|-- branches
|-- tags
|-- trunk (here there is my subproject source, also pom.xml file)
I've create project with its subproject, from svn URL, on teamcity server.
When I run Build on parent project it fail and return me the following error:
[Step 1/1] Error reading Maven project: Some problems were encountered while processing the POMs:
[ERROR] Child module /opt/buildAgent/work/ee114e0c77ee2c44/subproject of /opt/buildAgent/work/ee114e0c77ee2c44/pom.xml does not exist #
How can I say to parent-project-build where it find the child module?
Is there something else wrong?
Parent 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>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>MyProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>Foo</module>
</modules>
</project>
Child POM:
<?xml version="1.0"?>
<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>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>it.company.subproject</groupId>
<artifactId>subproject</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>subproject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</build>
</project>
EDIT:
I added new parameter (pathSubproject) to my parent pom.xml, so when I run the parent build it skipped the previous error, but now it crash when trying to resolve parent dependency on the subproject. So I added a new parameter also at subproject (parentPath) and I passed it to relativePath inside parent tag.
Non-resolvable parent POM: Could not find artifact it.company.project:MyProject:pom:1.0-SNAPSHOT and 'parent.relativePath'
I think that my subproject POM not resolve the properties that I put inside <relativePath tag.
Is possible pass a properties to relativePath tag?
Thanks

In the <modules/> section of your parent project's pom, each module listed is a relative path to the directory containing the module.
So if you don't want to change the directory structure, you should be able to refer to the trunk of your subproject using <module>subproject/trunk</module>.
This does seem a bit clumsy though. If you are using the aggregator / modules pattern, I would recommend that project and subproject are both in the same SVN respository. If that isn't appropriate, then your subproject might not really be a module, and should be a dependency or have project as its parent artifact.

I solve my problem by creating 2 profile in my parent pom, the first one builds the parent application with all submodules, while the latter build only the the parent application.
In TeamCiTY build configuration settings I specified (inside Additional Maven command line parameters) the profile that build only parent module, and after I built the parent Application.
After that I built the parent application I built all submodules, and then I was able to build parent application with all modules.
I'm not sure that this is the right way, but in my case it worked well.

Related

Read custom version config property from a property file and access it in pom.xml

I am working with maven projects . I want to read my version number from a property file and access this version variable into my pom.xml instead of updating each time in the 17.3-SNAPSHOT in the pom.xml . So when i want to update my version in a particular development sprint,the change should have only in the version number property in the property file and will be able to build jar file with the updated version . So I want to create a version config variable in an external property file
(example : /main/resources/version_config.properties) and access this in pom.xml for the build process .
<dependency>
<group Id>x.x.x</group Id>
<artifact Id>maven-model</artifact Id>
<version>2.0</version>
</dependency>
instead of using the above version value(2.0) between version tag , i want to get this value from a property file names xxx.properties (property like , version.config.value=2.0)
I tried the above solutions .Can any one help on on this ?
I suggest you to define the version of your application in a specific Maven project that you can use as parent Maven project.
From Maven documentation "Introduction to the POM" (Example 5) :
Example 5
The Scenario
Given the previous original artifact POMs again,
com.mycompany.app:my-app:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
com.mycompany.app:my-module:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
</project>
and this directory structure
.
|-- my-module
| `-- pom.xml
`-- parent
`-- pom.xml
The Solution
To do both project inheritance and aggregation, you only have to apply
all three rules.
com.mycompany.app:my-app:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>../my-module</module>
</modules>
</project>
com.mycompany.app:my-module:1's POM
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-module</artifactId>
</project>
NOTE: Profile inheritance the same inheritance strategy as used for the POM itself.

Retrieve all jars from Local jfrog Repository using Maven

I am hosting a Local Repository with 80+ Jar files which are related to our internal Project
Something like this
I want to add a tag in my Maven pom.xml where in I retrieve all the jar files in one shot when I create a new project in Eclipse.
These jars are static and will not change.
Can anyone please help in setting up this?
In Artifactory - "Set me Up", I can see this TAG, but its for pushing a final jar
You have at least two options:
1. Use a parent pom
Add all the 80 dependencies to a POM which 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>your.company</groupId>
<artifactId>ourDependencies</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging> <!-- IMPORTANT -->
<dependencies>
<!-- place here 80 dependencies -->
<dependency>
...
</dependency>
</dependencies>
<build> <!-- optional -->
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
<distributionManagement>
... <!-- optional -->
</distributionManagement>
</project>
In the project that needs the dependencies, add a <parent> element to the pom.xml:
<project>
<groupId>your.company</groupId>
<artifactId>newApplication</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging> <!-- or war or ... -->
....
<parent>
<groupId>your.company</groupId>
<artifactId>ourDependencies</artifactId>
<version>1.0.0</version>
</parent>
...
</project>
Keep in mind that every project can have only one parent.
2. Create an archetype
This way is more complex. You can create a simple project similar to "HelloWorld" which contains all the dependencies. Based on this project, you can create an archetype which serves as a template when you create a new Maven project.
More Informations:
Introduction to archetypes
archetype tutorial

project.build.sourceEncoding defined in Parent Pom Ignored in Child

Given a parent 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.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java-version>1.8</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<com.acme.dynamite-version>0.0.1-SNAPSHOT</com.acme.dynamite-version>
// etc
</properties>
</project>
and child 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.acme</groupId>
<artifactId>child</artifactId>
<version>dev-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.acme</groupId>
<artifactId>dynamite</artifactId>
<version>${com.acme.dynamite-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
The property, com.acme.dynamite-version, which is explicitly referenced in the child pom is resolved, however project.build.sourceEncoding is ignored. The Jenkins build of 'mvn clean install' throws a warning:
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
Is there a way to get the child pom to recognize project.build.sourceEncoding? This is not a multi module project, I am just trying to consolidate properties in one place
Properties defined in a parent POM are inherited in the child POM... but for that, the parent POM defining those properties needs to be installed before the child is built. And this is the issue here:
Your parent, having a version 0.0.1-SNAPSHOT, right-fully declares the property <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>. However, that version of the parent defining this property is not installed in your local repository.
When trying to build the child project, Maven will look-up any dependencies and parent POM in your local repo. It will find the version of the parent without that property and continue the build. Then, the maven-resources-plugin will emit this warning because no encoding have been set. (Setting the project.build.sourceEncoding also sets by default the encoding used by this plugin).
The solution is to build the parent first.
In a multi-module Maven project, you simply need to build the parent: Maven will order the reactor in such a way that dependant projects are built first; so in this case, the parent would be built first, and then the child (or module in this case), thereby ensuring that all properties defined in the parent are accessible to the child.
Outside of a multi-module Maven project, the idea is still the same, but you then need to perform two distinct builds: first the parent to install the right version into your local repository, and then the child. Note that when such parents are not used as aggregator projects, but more as building blocks consolidating common properties for children to inherit from, it would be preferable to have a distinct release cycle with it: consider making a release of your parent, so that every child can inherit that particular version.
You need to add the maven-resources-plugin in order to activate filtering, like here:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<configuration>
...
<encoding>UTF-8</encoding>
...
</configuration>
</plugin>
</plugins>
...
</build>

Maven versioning of multi-module projects with parent POM

This is a slightly different version of this previous question, in that I have separate multi-module and parent POMs: In a Maven project, how can I automatically update the version all child modules, plus the parent?
I am trying to update my POMs to go from a development snapshot version to a released version number. I have googled the issue to death, tried the release and version plug-in, and nothing seems to be able to handle my fairly simple setup.
Following published Maven best practices, and trying not to duplicate information when I can avoid to, I ended up with the structure below for my multi-module project.
There is a single version defined by the common pom-parent.xml; and B depends on A.
I find it a bit surprising that the standard plug-ins can't handle what seems to be a fairly basic setup, am I missing something?
None of the workarounds I have come up with are completely satisfactory:
define the product version as a property is a bit flaky, the same module source could get different versions because of a user settings.xml or other trick
merge the root pom.xml and pom-parent.xml and move the product-wide build steps I currently maintain in the root pom into a dedicated module; and hope that the std plug-ins will then work... not tried.
Any suggestion?
root/pom-parent.xml: parent of all the POMs below
<project...>
<groupId>acme</groupId>
<artifactId>ParentPom</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
root/pom.xml: multi-module projects with A and B as submodules
<project ...>
<parent>
<groupId>acme</groupId>
<artifactId>ParentPom</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>acme</groupId>
<artifactId>Product</artifactId>
<packaging>pom</packaging>
<modules>
<module>A</module>
<module>B</module>
</modules>
root/A/pom.xml:
<project ...>
<parent>
<groupId>acme</groupId>
<artifactId>ParentPom</artifactId>
<relativePath>../parent-pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>acme</groupId>
<artifactId>A</artifactId>
<packaging>jar</packaging>
root/B/pom.xml:
<project ...>
<parent>
<groupId>acme</groupId>
<artifactId>ParentPom</artifactId>
<relativePath>../parent-pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>acme</groupId>
<artifactId>B</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>acme</groupId>
<artifactId>A</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
If you have a structure like the following:
root
+-- pom.xml (1.0-SNAPSHOT)
!
+-- module1
! +-- pom.xml (1.0-SNAPSHOT)
+-- module2
+-- pom.xml (1.0-SNAPSHOT)
all modules (module1 and module2) using root as their parent like this:
<parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
If you want to factor out other default setup like pluginManagement or dependencyManagement for other projects as well you have to use a separate parent pom which must be a separate maven project which contains only the pom.xml. Furthermore this project will be deployed and released separately. If you do so you can use this as parent in the root pom of the above structure.
If you like to make a release you will go simply into the root folder of the above structure and the version number etc. will automatically incremented.
mvn -B release:prepare release:perform

Three-level pom (company - project - module) - problems with module project(s)

I am using Eclipse Indigo with m2e (which connects to an external binary of Maven 3.0.3).
Right now, the intended structure of my application is as follows:
Company-parent
--Project-parent
----Module1
----Module2
----ModuleN
I set up my poms such that Company-parent is the project of Project-parent, and Project-parent is the parent of all of the modules. The company-parent and the project-parent seem to be ok. Both are of packaging type POM.
The third level is where I start to encounter problems. I get a variety of maven errors, and all kinds of weird behavior, even with the simplest of module projects defined.
Company parent:
<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.scoresecret</groupId>
<artifactId>scs-global-parent</artifactId>
<version>1</version>
<packaging>pom</packaging>
</project>
Project parent:
<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>
<artifactId>scs-global-parent</artifactId>
<groupId>com.scoresecret</groupId>
<version>1</version>
</parent>
<artifactId>scs-model-parent</artifactId>
<groupId>com.scoresecret.model</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>scs-model-core</module>
</modules>
</project>
Module 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>
<parent>
<artifactId>scs-model-parent</artifactId>
<groupId>com.scoresecret.model</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>scs-model-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
I can't do "Maven -> Update Project Configuration", because when I do, I get this error:
Failure to find org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 in https://my.archiva.location/archiva/repository/internal was cached in the local repository, resolution will not be reattempted until the update interval of scs.internal has elapsed or updates are forced pom.xml /scs-model-core line 1 Maven Configuration Problem
Some other errors I'm receiving:
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.4.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.4.3 pom.xml /scs-model-core line 1 Maven Build Problem
Also receiving an error about m2e ignoring one of my plugin goals (from the company level pom) within the module. Am I missing something obvious here? Help!
Thanks :)
you shouldn't have the artifacts located like you described in a directory structure.
+-- Company-parent (pom.xml)
+-- Project-parent (pom.xml)
+----Module1 (pom.xml)
+----Module2 (pom.xml)
+----ModuleN (pom.xml)
To make a real good use of you company-parent (pom.xml) it should be helt into a separated area in version control and released separately in your repository manager (nexus, artifactory, archiva...). This will result in the following structure:
+-- Company-parent (pom.xml) (Separate Project)
The company-parent should be released as often as needed via the release-plugin. Lets assume we have released version 1.0 of the company-parent. The reason to have it separated is, cause the company-parent is used by many projects and not only by a single project.
and the real projects should be put into a separate folder (also in version control):
+-- Project-parent (pom.xml)
+----Module1 (pom.xml)
+----Module2 (pom.xml)
+----ModuleN (pom.xml)
So to use the company-parent in your project the project-parent has to look like:
<project....>
<modelVersion>4.0...</modelVersion>
<parent>
<artifactId>company-parent</artifactId>
<groupId>com.company.base</groupId>
<version>1.0</version>
</parent>
<packaging>pom</packaging>
<groupId>com.company.project1</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
...
<dependencyManagement>
<!-- Project specific dependencies -->
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<!-- Project specific plugins. Better use them of the company pom -->
</plugins>
</pluginManagement>
</build>
<modules>
<module>module1</module>
<module>module2</module>
<module>moduleN</module>
</modules>
..
Now let us take a look into a module which should look like this:
<project....>
<modelVersion>4.0...</modelVersion>
<parent>
<artifactId>project-parent</artifactId>
<groupId>com.company.project1</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>module1</artifactId>
<dependencies>...</dependencies>
<build>..</build>
You should reference the parent pom with explicit path:
<parent>
<artifactId>scs-model-parent</artifactId>
<groupId>com.scoresecret.model</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relateivePath>
</parent>
Otherwise, you need to reinstall the parent pom into the repository every time you change it.
Sounds like maven isn't able to download a plugin (org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3) from the repository https://my.archiva.location/archiva/repository/internal
Failure to find org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 in https://my.archiva.location/archiva/repository/internal was cached in the local repository, resolution will not be reattempted until the update interval of scs.internal has elapsed or updates are forced pom.xml /scs-model-core line 1 Maven Configuration Problem
If you browse to this URL in a browser, does it exist? I see it's using https - do you need a client cert or some form of basic auth credentials to access this url?
What are your current settings in your .m2/settings.xml show for repositories? Are you behind a company firewall or not connected to the internet which is forcing you to connect to a non-standard maven central repository?
It turns out, that my local repo contained files which ended with the extention ".lastUpdated" ... this was because I was having problems with authentication when I tried encrypting my maven passwords, so it wasn't downloading the dependencies. I deleted those files and simply ran "Maven > Update Dependencies" and it worked no problem, downloading the missing resources from my artifact repository.

Resources