Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建没有依赖项的jar A,并使依赖项目C下载此依赖项A所依赖的依赖项B_Java_Maven_Spring Boot_Jar - Fatal编程技术网

Java 创建没有依赖项的jar A,并使依赖项目C下载此依赖项A所依赖的依赖项B

Java 创建没有依赖项的jar A,并使依赖项目C下载此依赖项A所依赖的依赖项B,java,maven,spring-boot,jar,Java,Maven,Spring Boot,Jar,我已经成功地创建了一个不包含依赖项的jar。这个罐子A依赖于罐子B。我不想创建一个胖罐子。我只想让依赖项目调用它C来添加我的jar A作为依赖项,一旦添加了jar A,项目就应该拉入jar B 这可能吗 问题到此为止。以下是我迄今为止所做的尝试: 我所做的: 我首先与maven和gradle一起创建了胖罐子。现在它有了所有的依赖项,但是我自己的类被隐藏在其中的某个地方。依赖项目找不到我的类 然后我创建了一个不包含任何依赖项的jar。我分别与maven和gradle创建了它们。这解决了我的类找不到

我已经成功地创建了一个不包含依赖项的jar。这个罐子A依赖于罐子B。我不想创建一个胖罐子。我只想让依赖项目调用它C来添加我的jar A作为依赖项,一旦添加了jar A,项目就应该拉入jar B

这可能吗

问题到此为止。以下是我迄今为止所做的尝试:

我所做的:

我首先与maven和gradle一起创建了胖罐子。现在它有了所有的依赖项,但是我自己的类被隐藏在其中的某个地方。依赖项目找不到我的类

然后我创建了一个不包含任何依赖项的jar。我分别与maven和gradle创建了它们。这解决了我的类找不到的问题。但后来我遇到了另一个问题。我一运行这个项目,它就抱怨jarb丢失了。这是理所当然的,因为我从来没有把它包括在内

我将向您展示我的pom.xml

<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>
<groupId>custom-spring-boot-starter</groupId>
<artifactId>custom-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency> //THIS IS WHAT DEPENDENT PROJECT WILL NOT HAVE.
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-servicebus</artifactId>
        <version>0.9.7</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>10</release>
            </configuration>
        </plugin>
    </plugins>
</build>

是的,如果A对B有Maven依赖,那么当C依赖于A时,B会自动被拉入。这就是Maven传递依赖解析


请注意,这与脂肪罐无关。B不包括在A中,它只是在A的POM中作为依赖项提到。

我问这个问题时,并不知道一些非常重要的事情

当JAR被放入artifactory时,相应的.pom文件也必须放在它旁边的目录外,只需查看下面的链接即可了解目录结构。这个pom文件告诉依赖项目,您所依赖的jar本身需要某某依赖项

如果您执行mvn clean安装,它会自动将jar文件和pom文件安装在本地maven存储库中的正确位置

这个答案让我明白:


感谢所有尝试过的人。

Maven的依赖关系是可传递的。如果您使用Maven来构建C,它就会工作。由于您只使用Gradle拉取结果JAR,因此它无法知道该JAR还包含哪些内容。据我所知,这就是其他团队成员开发的其他JAR的工作方式。你能看一下我在问题中发布的屏幕截图吗?我在想,当gradle从web而不是本地引入依赖时,它可能会解决内部依赖。你怎么想?@rustyx我想答案就在这里:@rustyx我发布了我的答案:我用gradle把A拉进C。A在我的硬盘上。也许这就是为什么它没有引入可传递依赖关系的原因?A需要在Maven存储库中。如果您使用Maven或Gradle构建了,您可以将其部署到Maven存储库,如Maven本地存储库或公司Nexus/Artifactory。我正在研究它。谢谢JF。我想这就是答案所在:
<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>
<groupId>custom-spring-boot-starter</groupId>
<artifactId>custom-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>10</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-servicebus</artifactId>
        <version>0.9.7</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>10</release>
            </configuration>
        </plugin>
        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <executions>
                <execution>
                    <id></id>
                    <goals>
                        <goal>revision</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
            <configuration>
                <dateFormat>yyyy-MM-dd-HH:mm:ss</dateFormat>
                <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
                <prefix>git</prefix>
                <verbose>false</verbose>
                <generateGitPropertiesFile>true</generateGitPropertiesFile>
                <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                <format>json</format>
                <gitDescribe>
                    <skip>false</skip>
                    <always>false</always>
                    <dirty>-dirty</dirty>
                </gitDescribe>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Build-Jdk>${java.version} (${java.vendor} ${java.vm.version})</Build-Jdk>
                        <Digital-Voltage-Library-Version>${project.version}</Digital-Voltage-Library-Version>
                        <Build-Timestamp>${git.build.time}</Build-Timestamp>
                        <Build-Revision>${git.commit.id}</Build-Revision>
                        <Build-OS>${os.name} ${os.arch} ${os.version}</Build-OS>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
compile fileTree(dir: '/lib', include: 'custom-spring-boot-starter-0.0.1-SNAPSHOT.jar')