提问者:小点点

Maven/Docker-父工件的版本被用作依赖项的版本


所以我有一个带有以下pom. xml的Maven项目(交付记录导入器):

<?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">
<parent>
    <artifactId>microservices</artifactId>
    <groupId>**company_group_id**</groupId>
    <version>1.1.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>delivery-record-importer</artifactId>

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <main.class>company.app.DeliveryRecordImporterApp</main.class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>**company_group_id**</groupId>
        <artifactId>core</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                <resource>META-INF/spring.factories</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${main.class}</mainClass>
                                <manifestEntries>
                                    <Multi-Release>true</Multi-Release>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>${main.class}</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

该项目依赖于另一个名为core的项目,其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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>alpha</artifactId>
        <groupId>**company_groupId**</groupId>
        <version>1.1.5-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>core</artifactId>
    <name>${project.artifactId}</name>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <scm>
        ...
    </scm>

    <distributionManagement>
        ...
    </distributionManagement>
    
    <dependencies>
        <dependency>
          <groupId>com.azure.spring</groupId>
          <artifactId>azure-spring-boot-bom</artifactId>
          <version>4.0.0</version>
          <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-storage-blob</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <goals>deploy</goals>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-provider-gitexe</artifactId>
                        <version>1.12.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-api</artifactId>
                        <version>1.12.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

请注意,core有azure-storage-blob作为依赖项,并且这个azure依赖项依赖于一个名为jackson的库(版本2.13,我目前可以使用mvn依赖项:tree进行检查)。我项目中的pom. xmls都没有直接依赖于jackson。这个项目“交付记录导入器”在Docker容器上运行,来自以下Dockerfile:

FROM osgeo/gdal

RUN apt-get update && apt-get install -y openjdk-11-jre-headless

ENV LD_LIBRARY_PATH=/usr/share/java

ARG MODULE
ARG DIR
WORKDIR /
COPY ${DIR}${MODULE}/target/${MODULE}*.jar app.jar
EXPOSE 5000
CMD java -jar -Djava.util.concurrent.ForkJoinPool.common.parallelism=8 -Dspring.profiles.active=docker app.jar

但是这个容器上的服务给了我以下错误:

有人能解释一下为什么1.1.5-SNAPSHOT被指定为jackson包的版本,而1.1.5-SNAPSHOT在pom. xmls中明确表示为父artifactId版本,而jackson来自azure的依赖项安装为2.13?


共1个答案

匿名用户

我认为根本原因是azure sdk如何发现fasterxml版本:

杰克逊版本:

annotationsVersion = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.annotation.JsonProperty");
coreVersion = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.core.JsonGenerator");
databindVersion = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.databind.ObjectMapper");
xmlVersion = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.dataformat.xml.XmlMapper");
jsr310Version = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.datatype.jsr310.JavaTimeModule");
checkVersion(annotationsVersion, ANNOTATIONS_PACKAGE_NAME);
checkVersion(coreVersion, CORE_PACKAGE_NAME);
checkVersion(databindVersion, DATABIND_PACKAGE_NAME);
checkVersion(xmlVersion, XML_PACKAGE_NAME);
checkVersion(jsr310Version, JSR310_PACKAGE_NAME);
helpString = formatHelpString();
LOGGER.info(helpString);

语义版本:

try (JarFile jar = new JarFile(clazz.getProtectionDomain().getCodeSource().getLocation().getFile())) {
  Manifest manifest = jar.getManifest();
  versionStr = manifest.getMainAttributes().getValue("Implementation-Version");
  if (versionStr == null) {
     versionStr = manifest.getMainAttributes().getValue("Bundle-Version");
  }
  return parse(versionStr);
} catch (IOException | SecurityException ignored) {
  return createInvalid();
}

由于您使用的是maven-shad-pluginjar不再包含fasterxml库实际版本的信息。

您需要切换到新版本的azure sdk-他们半年前更改了发现机制或停止起诉maven-shad-plugin