Я бы предложил использовать Gradle вместо Maven. Ниже вы можете найти минимальный build.gradle
файл, который позволяет вам скомпилировать, протестировать и упаковать совместно используемую библиотеку Jenkins (и даже установить в репозиторий Maven, если вам нужно поделиться ею с другим проектом):
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'maven'
repositories {
mavenCentral()
}
sourceSets {
main {
groovy {
srcDirs = ['src', 'vars']
}
resources {
srcDirs = ['resources']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
compile 'com.cloudbees:groovy-cps:1.22'
compile 'org.codehaus.groovy:groovy-all:2.4.12'
// https://github.com/jenkinsci/JenkinsPipelineUnit
testCompile 'com.lesfurets:jenkins-pipeline-unit:1.1'
testCompile 'junit:junit:4.12'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
Этот минимальный build.gradle
файл использует jenkins-pipeline-unit
- инфраструктуру модульного тестирования для конвейеров Jenkins. Это очень удобно и облегчает жизнь в 10 раз.
Кроме того, вы можете проверить следующий проект шаблона Gradle для общей библиотеки Jenkins Pipeline - https://github.com/mkobit/jenkins-pipeline-shared-library-example Он поставляется со многими другими функциями, а также помогает поддерживать проект общей библиотеки.
Однако, если вам действительно нужно использовать Maven для этого, вы можете использовать следующее pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>jenkins-shared-library</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.cloudbees</groupId>
<artifactId>groovy-cps</artifactId>
<version>1.22</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.lesfurets</groupId>
<artifactId>jenkins-pipeline-unit</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/</sourceDirectory>
<testSourceDirectory>test/</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6.2</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>
<directory>${project.basedir}/src</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
<source>
<directory>${project.basedir}/vars</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
<testSources>
<source>
<directory>${project.basedir}/test</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</testSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Это более или менее эквивалентный файл build.gradle
.