我正在尝试将我的项目从gradle构建转换为maven构建。我可以从maven生成war文件,但是maven中的一些依赖项JAR的版本与Gradle的版本不同。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE')
classpath('org.apache.hive:hive-jdbc:2.0.0')
classpath('postgresql:postgresql:9.1-901-1.jdbc4')
classpath('org.apache.logging.log4j:log4j-core:2.8.2')
}
}
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
bootRepackage {
mainClass = 'com.rest.api.app'
}
apply plugin: 'war'
apply plugin: 'maven'
war {
baseName = 'app'
}
repositories {
mavenCentral()
}
configurations {
all*.exclude module: 'slf4j-log4j12'
all*.exclude module: 'log4j-slf4j-impl'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-starter-web'){
exclude module : 'spring-boot-starter-logging'
}
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.apache.lucene:lucene-snowball:3.0.3')
compile('org.apache.hive:hive-jdbc:2.0.0')
compile('postgresql:postgresql:9.1-901-1.jdbc4')
compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.8')
compile('com.fasterxml.jackson.core:jackson-databind:2.8.8.1')
compile('org.apache.logging.log4j:log4j-core:2.8.2'){
force=true
}
compile('org.apache.logging.log4j:log4j-api:2.8.2'){
force=true
}
compile group: 'org.apache.solr', name: 'solr-solrj', version: '5.2.1'
compile group: 'org.apache.lucene', name: 'lucene-analyzers-common', version: '6.4.0'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.6'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.4'
compile group: 'org.apache.commons', name: 'commons-text', version: '1.0'
}
task writeNewPom {
doLast {
pom {
project {
}
}.writeTo("$buildDir/mavenpom.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>com.app</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.2.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-pool/commons-pool -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-snowball</artifactId>
<version>3.0.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</exclusion>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.8.8</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.2.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>6.4.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.2.RELEASE</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_05</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestEntries>
<ChangesetNum>${tfs.changeset.num}</ChangesetNum>
</manifestEntries>
</archive>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<mainClass>com.rest.api.app</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<jdk.version>1.8</jdk.version>
<tfs.changeset.num>0</tfs.changeset.num>
</properties>
</project>
Gradle Maven
slf4j-api-1.7.24.jar slf4j-api-1.7.5.jar
servlet-api-2.5.jar servlet-api-2.4.jar
metrics-core-3.1.3.jar metrics-core-3.1.0.jar
log4j-web-2.7.jar log4j-web-2.4.1.jar
log4j-1.2-api-2.7.jar log4j-1.2-api-2.4.1.jar
log4j-1.2.17.jar log4j-1.2.16.jar
junit-4.12.jar junit-4.11.jar
json-20140107.jar json-20090211.jar
joda-time-2.9.7.jar joda-time-2.5.jar
jackson-xc-1.9.13.jar jackson-xc-1.8.3.jar
jackson-jaxrs-1.9.13.jar jackson-jaxrs-1.8.3.jar
jackson-core-2.8.7.jar jackson-core-2.8.8.jar
httpmime-4.5.3.jar httpmime-4.4.1.jar
hadoop-yarn-common-2.6.0.jar hadoop-yarn-common-2.5.1.jar
hadoop-auth-2.6.0.jar hadoop-auth-2.5.1.jar
guava-16.0.1.jar guava-14.0.1.jar
gson-2.8.0.jar gson-2.2.4.jar
derby-10.13.1.1.jar derby-10.10.2.0.jar
commons-logging-1.2.jar commons-logging-1.1.3.jar
commons-digester-2.1.jar commons-digester-1.8.jar
commons-collections-3.2.2.jar commons-collections-3.2.1.jar
commons-codec-1.10.jar commons-codec-1.6.jar
commons-beanutils-1.9.3.jar commons-beanutils-1.7.0.jar
classmate-1.3.3.jar classmate-1.3.1.jar
cglib-2.2.1-v20090111.jar <Not available>
问题1:为什么上述罐子的版本不一样?
问题2:为什么使用Gradle构建的战争有“cglib-2.2.1-v20090111.jar”,而使用Maven构建的战争却没有?
如果依赖树中出现多个版本,Maven和Gradle遵循不同的规则来选择可传递依赖的版本。Maven通常使用最近的外观(距离树的根的步数),而Gradle默认为最高版本。
在Maven中,您可以通过使用DependencyManagement来修复冲突的可传递依赖的版本。
在命令行中,我需要构建一个没有依赖项的可执行jar。当前的“gradle build”命令给了我一个带有依赖项的jar。 在StackOverflow上找不到这个。如果是重复的问题,指给我看。谢谢。
我不断得到原因:java.nio.file.nosuchfileException:C:\Program Files\Apache Software Foundation\Tomcat 9.0\WTPWebApps\WebApp\WEB-INF\lib\Jackson-DataBind-2.9.6.jar Exception。我的pom.xml文件中有2.9.6版本的依赖项,但Maven depe
我一直在使用gradle作为Springboot,它过去很好,但gradle的构建突然停止了工作。我不断收到错误,说找不到依赖项 这是分级代码: 我得到的错误是: 无法解析组织。springframework。启动:spring启动依赖项:2.4。1.无法解析io。关键的。Spring云:spring云服务依赖项:2.4。1.无法解析组织。springframework。云:spring云依赖项:
我正在使用Gradle构建系统开发一个IntelliJ插件。这个插件使用一个公共模型,它是一个maven项目。 我已经将mavenLocal包含在我的gradle存储库中,并且还在“dependencies”中添加了编译时依赖项。 代码编译得很好,但我在运行时得到了java.lang.NoClassDefoundError。当我检查gradle中的依赖项时,它并没有列出本地maven jar(模型
我。 我有一个名为的模块,我希望将它的所有依赖项打包到一个JAR中。我不想每次都创建fat big jar,并将其与应用程序代码一起部署。我的应用程序jar的大小<1 MB,但依赖性>20 MB 在我的服务器上,我将运行我的应用程序,如下所示: 当我更改应用程序代码时,我只需要将部署到我的服务器,并且只有当我更改依赖项时才需要上传(这是非常罕见的)。 有很多关于如何使用java源代码构建fat j
我将给你一个关于我的文件的概述: 设置。分级: Build.Gradle: 注意:我以为没有将依赖项添加到类路径中,但我不确定这一点。但是,我希望Intellij将依赖项添加到类路径中(或者在清单文件中声明) 但是,这会创建一个zip/tar,其中包含一个执行脚本和一个bin文件夹,这不是我的本意。 所以我开始在谷歌上搜索了好几个小时,但我找不到解决问题的方法。