> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flexagon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# build(Mule)

> The buildMule operation allows for building Mule projects, whether they are Maven projects or not. It automatically copies the completed zip file over

The buildMule operation allows for building Mule projects, whether they are Maven projects or not. It automatically copies the completed zip file over to the internal artifact repository. It should be used in build workflows.

<table><colgroup><col /><col /></colgroup><tbody><tr><th>**Maven Projects**</th><th>**Non-Maven Projects**</th></tr><tr><td> If a pom.xml is found in the projectPath, it will be run with Maven, using the `package` lifecycle. Any tests will be run during the build process. The output of the tests will be in the plugin execution log.If more control over the lifecycles or arguments is required, the [runMaven](https://docs.flexagon.com/flexdeploy-11-2-documentation/flexdeploy-plugin-guides/flexdeploy-maven-plugin-guide/runmaven.md) operation works exactly the same, except that it doesn't save the artifact to the artifact repository automatically. This can be done with the File - [saveArtifacts](https://docs.flexagon.com/flexdeploy-11-2-documentation/flexdeploy-plugin-guides/flexdeploy-file-plugin-guide/saveartifacts.md) operation.</td><td>This operation should run on the Mule server where the project will be deployed. This allows the project's build to be a more complete test of the environment.If the project is not a Maven project, it will be built using javac and other command line tools.Make sure that the JDK HOME specified on the endpoint is a JDK of the required version.The Mule Home (`FDMULE_HOME)` property is used to find the libraries that are necessary to compile the Mule project.</td></tr></tbody></table>

#   

Target Properties

<table><colgroup><col /><col /><col /><col /></colgroup><tbody><tr><th>**Property Name**</th><th>**Property Code**</th><th>**Required**</th><th>**Description**</th></tr><tr><td>Mule Home</td><td>`FDMULE_HOME`</td><td>If it is not a Maven Project.</td><td>Path to a Mule Server Installation</td></tr><tr><td>Maven Home</td><td>`FDMVN_MAVEN_HOME`</td><td>If it is not a Maven Project.</td><td>If it is desired to use an external Maven, fill in the Maven Home here. Otherwise, the internal Maven 3.9.11 will be used.</td></tr><tr><td>Maven Environment Script</td><td>`FDMVN_MAVEN_ENV_SCRIPT`</td><td>If it is not a Maven Project.</td><td>If necessary, provide a script to source variables for use by the Maven Plugin.</td></tr><tr><td>Mule Type</td><td>`FDMULE_TYPE`</td><td>For Cloudhub 2.0</td><td>Mule Install Type</td></tr></tbody></table>

# Inputs

<table><colgroup><col /><col /><col /><col /></colgroup><tbody><tr><th>**Input Name**</th><th>**Input Code**</th><th>**Required**</th><th>**Description**</th></tr><tr><td>Mule Project Path</td><td>`FDMULE_PROJECT_PATH`</td><td>No</td><td>This is the folder that typically is named for your application and contains your \[src] folder. Relative paths are sourced from the `FD_TEMP_DIR`.</td></tr><tr><td>http.port</td><td>`FDMULE_HTTP_PORT`</td><td>No</td><td>HTTP port to use when running Maven tests. This should be a different number than the one that is usually used to run the application on the server. This only works if `${http.port}` is used in your HTTP Connector.</td></tr><tr><td>Additional Maven Arguments</td><td>`FDMULE_MVN_ARGS`</td><td>No</td><td>Space-delimited list of additional Maven arguments (e.g. -e -X)</td></tr></tbody></table>

## CloudHub 2.0 Build Process

* In CloudHub 2.0 (From 10.0.0.2), the build and deployment process is slightly different from other Mule deployment approaches. During the build phase Maven does two main things

  * It creates the Mule application artifact (JAR file).

  * It pushes that artifact to MuleSoft Exchange (repository).

* To push the artifact to MuleSoft Exchange, credentials are required. Maven reads these credentials from the .m2/settings.xml file.

* So we need to update the .m2/settings.xml file with the required credentials. So we need to update the .m2/settings.xml file with the required credentials.

* By default, Maven uses the settings.xml file inside the .m2 folder. If we want Maven to use a different settings.xml file instead of the default one, we can pass it as an argument while running Maven. (-s /u01/mule-settings.xml). This tells Maven to use the specified settings.xml file instead of the default .m2/settings.xml.

* Know more about it here [https://docs.mulesoft.com/exchange/to-publish-assets-maven](https://docs.mulesoft.com/exchange/to-publish-assets-maven)

Sample Setting.XML

```
<settings
	xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<servers>
		<!-- Exchange authentication -->
		<server>
			<id>anypoint-exchange-v3</id>
			<username>Provide user name</username>
			<password>Provide user password</password>
		</server>
		<server>
			<id>MuleRepository</id>
			<username>Provide user name</username>
			<password>Provide user password</password>
		</server>
	</servers>
	<profiles>
		<profile>
			<id>anypoint</id>
			<properties>
				<anypoint.orgId>Provide Org Id</anypoint.orgId>
				<anypoint.env>Sandbox</anypoint.env>
			</properties>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>anypoint</activeProfile>
	</activeProfiles>
</settings>
```

## FlexDeploy Build Integration

The source POM file should contain placeholder values for the artifact name and artifact version. During the build, FlexDeploy replaces these placeholders with actual values. This ensures that the artifact name and artifact version used during the build are the same ones used during deployment.

Example POM Configuration

```
<!--
The POM must use placeholders for project name (FDMULE_APP_NAME)
and version (FD_PROJECT_VERSION).

FlexDeploy injects these values during build so the artifact
published to Exchange uses the same name and version
that will later be used during deployment.
-->

<artifactId>${FDMULE_APP_NAME}</artifactId>
<version>${FD_PROJECT_VERSION}</version>
```

# Artifacts

This operation produces artifacts that will be stored in the artifacts repository.

# Endpoint Selection

This operation will select all available endpoints associated to the Target.  

# Endpoint Execution

This operation will execute on any one of the selected endpoints and will be random in the determination of which one.
