了解AEM项目如何使用Maven构建,以及在创建您自己的项目时必须遵守的标准。
要使用Cloud Manager成功构建和部署AEM项目,需要遵循以下准则:
pom.xml
文件。 此 pom.xml
文件可以引用任意数量的子模块(这些子模块又可能具有其他子模块等) 视需要。pom.xml
文件。
.zip
文件,包含在名为 target
.
.zip
文件(也包含在名为 target
),其目录名为 conf
和 conf.d
.在某些有限情况下,在Cloud Manager内运行时,您可能需要略微改变构建过程,而不是在开发人员工作站上运行。 对于这些情况, Maven用户档案 可用于定义在包括Cloud Manager在内的不同环境中,内部版本应有何不同。
在Cloud Manager内部版本环境中,激活Maven配置文件的方法是:查找 CM_BUILD
环境变量。 同样,应通过查找此变量的缺失来完成仅在Cloud Manager构建环境之外使用的配置文件。
例如,如果您希望仅在Cloud Manager中运行内部版本时才输出简单消息,则可以执行此操作。
<profile>
<id>cmBuild</id>
<activation>
<property>
<name>env.CM_BUILD</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<echo>I'm running inside Cloud Manager!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
要在开发人员工作站上测试此配置文件,您可以在命令行中启用它(使用 -PcmBuild
)或集成开发环境(IDE)中。
如果您希望仅在内部版本在Cloud Manager之外运行时才输出简单消息,则可以执行此操作。
<profile>
<id>notCMBuild</id>
<activation>
<property>
<name>!env.CM_BUILD</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<echo>I'm running outside Cloud Manager!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
受密码保护的Maven存储库中的对象只应非常谨慎地使用,因为通过此机制部署的代码当前并未在所有 代码质量规则 在Cloud Manager的质量门户中实施。 因此,它只应用于极少数情况下以及未绑定到AEM的代码。 建议还应将Java源以及整个项目源代码与二进制文件一起部署。
要在Cloud Manager中使用受密码保护的Maven存储库,请执行以下操作:
当Cloud Manager构建过程开始时:
<servers>
此文件中的元素将合并到默认 settings.xml
文件。
adobe
和 cloud-manager
视为保留,不应被自定义服务器使用。central
将永远不会被Cloud Manager镜像。<repository>
和/或 <pluginRepository>
元素内部 pom.xml
文件。<repository>
和/或 <pluginRepository>
元素将包含在 特定于Cloud Manager的配置文件,尽管这并非严格必要。例如,假设存储库位于 https://repository.myco.com/maven2
,则Cloud Manager应使用的用户名为 cloudmanager
,密码为 secretword
. 您将采取以下步骤。
将密码设置为管道中的密钥。
$ aio cloudmanager:set-pipeline-variables PIPELINEID --secret CUSTOM_MYCO_REPOSITORY_PASSWORD secretword`
在 .cloudmanager/maven/settings.xml
文件。
<?xml version="1.0" encoding="UTF-8"?>
<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>
<server>
<id>myco-repository</id>
<username>cloudmanager</username>
<password>${env.CUSTOM_MYCO_REPOSITORY_PASSWORD}</password>
</server>
</servers>
</settings>
最后,在 pom.xml
文件:
<profiles>
<profile>
<id>cmBuild</id>
<activation>
<property>
<name>env.CM_BUILD</name>
</property>
</activation>
<repositories>
<repository>
<id>myco-repository</id>
<name>MyCo Releases</name>
<url>https://repository.myco.com/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>myco-repository</id>
<name>MyCo Releases</name>
<url>https://repository.myco.com/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
最好将Java源与二进制文件一起部署到Maven存储库。
为此,请在项目中配置maven-source-plugin 。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
最好将整个项目源与二进制文件一起部署到Maven存储库。 这允许重建确切的对象。
为此,请在项目中配置maven-assembly-plugin。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>project-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
在Cloud Manager中,内部版本可能会生成任意数量的内容包。 出于各种原因,可能需要生成内容包,但不部署它。 例如,在构建仅用于测试的内容包时,或者在构建过程中的其他步骤(即,作为其他包的子包)中重新打包的内容包时,可能会出现这种情况。
为了适应这些情况,Cloud manager将在构建内容包的属性中 cloudManagerTarget
查找名为 的属性。 如果此属性设置为 none
,则会跳过并且不部署包。
设置此属性的机制取决于内部版本生成内容包的方式。 例如,使用 filevault-maven-plugin
您可以按如下方式配置插件。
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<properties>
<cloudManagerTarget>none</cloudManagerTarget>
</properties>
<!-- other configuration -->
</configuration>
</plugin>
的 content-package-maven-plugin
具有类似的配置。
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<properties>
<cloudManagerTarget>none</cloudManagerTarget>
</properties>
<!-- other configuration -->
</configuration>
</plugin>
在许多情况下,会将相同的代码部署到多个AEM环境。 如果Cloud Manager检测到在多个全堆栈管道执行中使用相同的git提交,则将尽可能避免重建代码库。
启动执行时,将提取分支管道的当前HEAD提交。 提交哈希在UI中和通过API可见。 成功完成构建步骤后,将基于提交哈希存储生成的工件,并可在后续管道执行中重复使用。
如果包位于同一程序中,则包可跨管道重复使用。 在查找可重复使用的包时,AEM会删除分支并在分支之间重复使用工件。
当重复使用时,构建和代码质量步骤会被有效地替换为原始执行的结果。 生成步骤的日志文件将列出最初用于生成对象的工件和执行信息。
以下是此类日志输出的示例。
The following build artifacts were reused from the prior execution 4 of pipeline 1 which used commit f6ac5e6943ba8bce8804086241ba28bd94909aef:
build/aem-guides-wknd.all-2021.1216.1101633.0000884042.zip (content-package)
build/aem-guides-wknd.dispatcher.cloud-2021.1216.1101633.0000884042.zip (dispatcher-configuration)
代码质量步骤的日志将包含类似信息。
请考虑您的计划有两个开发渠道:
foo
bar
两个分支位于同一提交ID上。
请考虑您的计划有两个分支:
foo
bar
两个分支具有相同的提交ID。
foo
.bar
.在这种情况下,来自 foo
将重新用于生产管道,因为已识别相同的提交哈希。
如果需要,可以通过设置管道变量来禁用特定管道的重复使用行为 CM_DISABLE_BUILD_REUSE
to true
. 如果设置了此变量,则仍会提取提交哈希,并且将存储所生成的工件以供日后使用,但之前存储的任何工件将不会重复使用。 要了解此行为,请考虑以下情景。
becdddb
. 执行成功,并且会存储所生成的工件。CM_DISABLE_BUILD_REUSE
变量。becdddb
,由于 CM_DISABLE_BUILD_REUSE
变量。f6ac5e6
. 执行成功,并且会存储所生成的工件。CM_DISABLE_BUILD_REUSE
变量。f6ac5e6
,则这些工件将被重复使用。CM_DISABLE_BUILD_REUSE
当Cloud Manager决定重复使用之前创建的内部版本对象时,不会考虑使用该对象。