Reputation: 2449
I am new to Maven, and i am working on a project that have one or more dependencies on my other projects.
Example: I have 3 maven projects.
Both MyProject and MyProjectOther are independent of each other and do not have much to do with each other, but they both have a dependency on MyProjectCommon. (MyProjectOther dose not matter much to this question, just included it to show that MyProjectCommon is used in other projects)
Locally i can make this work, i have a workspace where i have both packages. I understand this is because Maven stores MyProjectCommon in a local repository.
Both projects (MyProject and MyProjectCommon) have their own GitHub repository, and my AWS CodeBuild is directed to build the MyProject repository. This fails as MyProjectCommon dose not exists for AWS CodeBuild.
MyProject 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/maven-v4_0_0.xsd">
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>myproject</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject.common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
MyProjectCommon 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/maven-v4_0_0.xsd">
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject.common</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>myproject.common</name>
<url>http://maven.apache.org</url>
</project>
Upvotes: 5
Views: 2866
Reputation: 636
Unfortunately there is no easy way of doing this on any CI system that does not understand how underlying build dependencies are resolved and/or have 'always consistent' cached artifacts.
You do have couple of options here though. First option is to publish your artifact from the library build. You'll in this case have to setup multiple projects in CodeBuild, one for MyProject and other for MyProjectCommon. Builds for MyProjectCommon would publish artifacts to S3 (codebuild can do this) and then builds for MyProject can download the published artifact from S3 (you can also replace S3 with maven repositories but you'll have to publish the artifacts).
Other more saner option is to use maven modules to solve this issue (maven reactor) and create single repository for MyProjectCommon and MyProject. Essentially your projects end up under same repository and are built in the dependency order as specified in the pom of individual projects. Here's more documentation on the maven modules https://maven.apache.org/guides/mini/guide-multiple-modules.html
In the example you have, you'll still keep the pom file for MyProject and MyProjectCommon, but create another parent pom that defines both MyProject and MyProjectCommon as modules. You can then create CodeBuild project for this repository and run for example 'mvn install' which will compile both MyProjectCommon and MyProject in dependency order. You'll have an option to publish multiple artifacts from your build in CodeBuild or single zip with artifacts for both MyProject and MyProjectCommon.
I hope this helps.
Upvotes: 2