我有一个用 Maven 构建的 Java 应用程序。我们的CI系统(Bamboo)配置为使用Maven 3.1.1,我本地使用Maven 3.5。我们到处都在使用 Java 8u152;我也可以使用 8u144 重现该问题。
今天,在我对 Java 代码进行了微不足道的更改后,我们开始收到此错误(路径和项目名称被混淆):
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 35 source files to /bamboo/bamboo-home/xml-data/build-dir/ASP-CAS-CJT/project/service/target/test-classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.036s
[INFO] Finished at: Tue Feb 13 15:15:51 EST 2018
[INFO] Final Memory: 26M/715M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project project-name: Compilation failure -> [Help 1]
[ERROR]
[ERROR] To see …Run Code Online (Sandbox Code Playgroud) 我的问题是我有一个多模块maven构建,其中一个部分由swagger作为spring引导应用程序生成.第二个模块应该扩展生成的代码并最终启动.当我使用maven编译时,第二个项目在生成的代码中找不到类.我检查了jar,并且在构建jar时类文件最终在BOOT-INF目录中.我怀疑这是问题所在.编译代码的最佳解决方案是什么?
父母pom
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxx</groupId>
<artifactId>applications</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>project1-connector</name>
<artifactId>project1-connector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<developerConnection>scm:git:ssh://git@xxx.com:7999/bla/project1-java-repo.git</developerConnection>
</scm>
<properties>
<majorVersion>1</majorVersion>
<minorVersion>0</minorVersion>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<language>spring</language>
<configurationFile>${project.basedir}/src/main/resources/apiConfig.json</configurationFile>
<output>${project.basedir}/project1-api</output>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>project1-api</module>
<module>project1-backend</module>
</modules>
Run Code Online (Sandbox Code Playgroud)
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<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.xxx</groupId>
<artifactId>project1-api</artifactId>
<packaging>jar</packaging>
<name>project1-api</name>
<version>1.0.1</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.7.0</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version> …Run Code Online (Sandbox Code Playgroud) 我有一个企业应用程序,我正在从Ant构建转换为Maven.它几乎完全转换; 这是我需要解决的最后一件事.应用程序打包为一个EAR文件,其中包含两个WAR,并具有一个JAR模块,该模块提供应用程序的所有核心功能.
我正在使用Freemarker模板库来生成应用程序发送的自动电子邮件的消息正文.Freemarker需要将*.ftl模板文件放在类路径上,因为这是一个不是特定于一个WAR或另一个WAR的核心应用程序功能,所以它需要在JAR中.
定义JAR的Maven模块具有以下POM:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<relativePath>../../pom.xml</relativePath>
<groupId>com.company.project</groupId>
<artifactId>projectName</artifactId>
<version>1.8.0</version>
</parent>
<artifactId>core</artifactId>
<packaging>jar</packaging>
<name>Core Application</name>
<profiles>
<!-- snip -->
</profiles>
<dependencies>
<!-- snip -->
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.ftl</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<!-- snip -->
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
*.ftl文件位于src/main/resources/template /,其中一些位于template /中的子目录中.src/main/resources中还有其他文件 - 一些.properties和一些.xml,一些位于根目录,一些位于目录结构下.
当我在这个模块(或父模块)上运行包阶段时,作为构建过程的一部分创建的目标/ classes目录包含模板目录,该模板目录又包含所有*.ftl,*.xml和*具有适当目录结构的.properties文件.如果我手动JAR这个目录,一切都很完美.
这里变得奇怪而且我迷路了:当maven-jar-plugin创建JAR时,它包含XML和属性文件,但是JAR中完全没有模板目录,并且其内容无处可寻.
如您所见,我尝试明确地包括**/*.ftl.它没有任何区别; 我可以排除整个"包含"标记,我得到完全相同的行为.
我正在使用Maven 3.0.5和maven-jar-plugin 2.4.
我正在私有 GitHub 存储库和 Jenkins 构建之间设置 webhook 集成。我专门使用 Job DSL groovy 脚本配置作业(我愿意切换到另一种编程作业配置机制,但我不会接受任何要求我手动配置作业的答案)。II 想设置一个提交状态上下文和一组基于构建状态的自定义消息。
Jenkins 中嵌入的Job DSL API 文档没有帮助,只给了我这个签名:githubPullRequest(Closure closure),但没有告诉我如何构建合适的闭包。
以下是我的工作 DSL 的相关部分:
triggers {
githubPush()
githubPullRequest {
useGitHubHooks()
buildStatus {
completedStatus('SUCCESS', 'Build succeeded!')
completedStatus('FAILURE', 'Build failed. ')
completedStatus('ERROR', 'Build errored. This is probably a problem with Jenkins or related infrastructure and not an issue with your code changes.')
}
}
}
(...)
scm {
git {
remote {
github('privateorg/myrepo', 'ssh')
credentials('my-credential-id')
refspec('+refs/pull/*:refs/remotes/origin/pr/*')
}
branch('${sha1}')
}
} …Run Code Online (Sandbox Code Playgroud) 上下文:我的团队正在致力于使我们的 Java 服务套件具有容器化和动态可扩展性。为了实现这一点,我们的计划是使用由 etcd 支持的 Envoy,以及Envoy 文档中描述的自定义构建端点发现服务,使用基于v2 gRPC 的 API。然后,我们将为每个服务生成 Docker 镜像,并使用 Kubernetes 部署/管理它们。
我们使用 Maven 作为构建系统。我非常精通 Maven,但这是我第一次使用 gRPC 或协议缓冲区。
我使用 Spring Boot 为我的服务创建了一个存根,Jetty 提供了一些用于管理的 REST 和 JMX 端点。在介绍 protobuf 之前,存根构建并运行得很好。
我已经下载了Envoy data-plane-api并将 API 定义文件(**/*.proto)检查到我的项目 src/main/proto 下,保持下载的目录结构(例如 src/main/proto/特使/api/v2/eds.proto)。(附带问题:我需要 BUILD 文件吗?)
最后,我想要一个独立的 Maven 构建,它可以读取这些文件并生成 Java 类。构建需要在 Windows 和 OS X 机器上运行,以便它适用于开发人员,并在 Linux 机器上运行,以便它在我们的 CI (Bamboo) 中运行。它只需要一个 JDK、一个 Maven 安装和一个 Maven 存储库。(我们有一个Artifactory实例,如有必要,我可以上传其他方式无法在线获取的工件。)
到目前为止,我所拥有的似乎可以实现我的便携性目标:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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"> …Run Code Online (Sandbox Code Playgroud) 我正在编写 Bash 脚本。在其中,有几次我需要解析一些 JSON。我通常的做法如下:
MY_JSON=$(some command that prints JSON to stdout)
RESULT=$(python -c "import json,sys;data=json.load(sys.stdin); python code here that prints out the value(s) I need")
Run Code Online (Sandbox Code Playgroud)
这往往效果很好。然而,昨天我遇到了一个问题。我有以下代码:
MY_JSON=$(command that returns JSON containing an array of IDs)
IDS=$(echo "${MY_JSON}" | python -c "import json,sys;data=json.load(sys.stdin); for a in data['array']: print(a['id'])")
Run Code Online (Sandbox Code Playgroud)
当我运行该代码时,出现“语法错误”,插入符号指向fin for。
在我的谷歌搜索中,我发现的一切都表明,当您在语句的第一个字符上遇到语法错误时,通常意味着您在前一个语句中搞砸了一些事情。但是,如果我完全删除 for 循环,则不会出现语法错误。所以,很明显,问题出在循环上。
我做错了什么?语法错误怎么可能是有效关键字的第一个字符?
我最终找到了答案,我将在下面发布该答案以帮助其他试图构建涉及for循环的Python 单行程序的人——但我希望有人能给出更好的答案,也许使用理解(我不完全理解)或其他东西而不是 for 循环,以便我实际上可以在一行中完成此操作。使用 Python 以外的语言也是可以接受的,只要它在 Linux 主机上通常可用。
需要明确的是,我会寻找使用真正的JSON解析方案,用你喜欢的字符串操作工具(不是有些近似sed,awk等),这将是脆弱的对于喜欢的东西是否适合打印的JSON。