我不了解Java,但是尝试使用teamcity for CI / CD测试一个Java项目,该问题我无法触发构建来生成artifacts
,这对于部署另一个构建配置至关重要。
那么有人可以提供一个示例性的Java项目,该项目在以teamcity构建时可以产生artifacts
吗?
编辑:下面有更多详细信息:
项目树:
└───src
└───main
└───java
└───com
└───mycompany
└──app
最后一个文件夹app
包含一个名为App.java
的文件,其内容如下:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
System.out.println("A NullPointerException is a drag...");
Object myObject = null;
/**
* Checker prevents this from compiling...
*/
// System.out.println("myObject: " + myObject.toString());
/**
* ... which is simply fantastic. It shows:
*
* error: [dereference.of.nullable] dereference of possibly-null
* reference myObject
*
* http://checkerframework.org
*/
System.out.println("... but thankfully, Checker has our back: http://checkerframework.org");
}
我正在尝试构建hello
世界项目,是从Internet复制的,我无法验证此源代码及其工作方式。
pom.xml
的Maven与src
在同一文件夹中构建:
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<!-- This property will be set by the Maven Dependency plugin -->
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>jdk8</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.mycompany.app.App</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mycompany.app.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- This plugin will set the properties values using dependency information -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<!-- Add all the checkers you want to enable here -->
<annotationProcessors>
<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<!-- location of the annotated JDK, which comes from a Maven dependency -->
<arg>-Xbootclasspath/p:${annotatedJdk}</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
当我在本地git服务器下添加该项目并将其推送到teamcity(在源代码中添加一些空格)以触发构建时,build step
来自{{1}的auto-detected
构建配置功能}构建步骤(添加新构建步骤时,我选择了maven
)
编辑2:当我触发在teamcity上运行构建时,构建成功,但是maven
被隐藏,构建该项目后,我需要在artifacts
中生成.jar or .war
包。
编辑3:在artifacts
中有或没有**/*.jar
的情况下,运行build都不会产生artifacts
工件,以下是配置:
感谢您的帮助。我现在呆了几天。
答案 0 :(得分:1)
您将需要告诉Team City构建工件在哪里。在构建配置中,有一个(Arifact路径)字段,该字段将使用蚂蚁符号。例如显示所有jar / war文件。
**/*.war
**/*.jar
这将扫描整个项目中的war或jar文件。通常将它们放在maven用来构建源代码的/target
文件夹中。