Gradle 構建去除一些影響正常運行的jar

使用gradle構建項目在引用私有服務的時候,會引入一些影響系統啓動的jar。例如引入了jooq包而沒有配置數據源,則項目無法啓動。所以需要去除對應的jar。具體配置如下:

在build.gradle文件中配置去除對應文件

configurations {
	all*.exclude module: 'hibernate-validator'
	all*.exclude module: 'jooq'
	all*.exclude module: 'org.springframework.boot:spring-boot-starter-logging'
	all*.exclude module: 'org.jooq:jooq-meta'
	all*.exclude module: 'mysql-connector-java'
	all*.exclude module: 'tomcat-jdbc'
}

若不知道如何寫exclude module 後的包。從如下地方找。

 

總體配置如下

buildscript {
	ext {
		springBootVersion = '1.5.4.RELEASE'
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
	}
	repositories {
		// 優先使用國內源
		maven {
			//url 'https://maven.aliyun.com/repository/public'
			url "http://115.28.148.171:8082/nexus/content/groups/public/"
		}
		mavenCentral()
	}
}

plugins {
	id 'java'
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
group = 'com.dlzb.assist'
version = '0.0.1-SNAPSHOT'

// 指定java版本
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
	// 使用國內的源
	//maven { url 'https://maven.aliyun.com/repository/public' }
	maven {
		url "http://115.28.148.171:8082/nexus/content/groups/public/"
	}
	mavenCentral()
}


dependencies {
	compile "org.springframework.boot:spring-boot-starter"
	compile 'org.springframework.boot:spring-boot-starter-actuator'
	compile 'org.springframework.boot:spring-boot-starter-web'
	compile 'org.springframework.boot:spring-boot-starter-integration'
	compile 'org.springframework.integration:spring-integration-file:4.3.5.RELEASE'
	compile 'org.springframework.boot:spring-boot-devtools'
	compile 'com.google.code.gson:gson:2.8.0'
	compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-xml-provider:2.5.0"
	compile "org.apache.commons:commons-lang3:3.7"
	compile "org.springframework.boot:spring-boot-starter-websocket:2.0.2.RELEASE"
	compile "org.springframework.boot:spring-boot-starter-cache:2.0.0.RELEASE"
	compile "net.sf.ehcache:ehcache:2.10.2"
	compile "com.google.guava:guava:25.1-jre"
	compile "joda-time:joda-time:2.9.9"
	compile "commons-httpclient:commons-httpclient:3.1"
	compile "cn.togeek.base:service:2.0.0-SNAPSHOT"
	compile "cn.hutool:hutool-all:4.0.8"
	testCompile("org.springframework.boot:spring-boot-starter-test")
}

configurations {
	all*.exclude module: 'hibernate-validator'
	all*.exclude module: 'jooq'
	all*.exclude module: 'org.springframework.boot:spring-boot-starter-logging'
	all*.exclude module: 'org.jooq:jooq-meta'
	all*.exclude module: 'mysql-connector-java'
	all*.exclude module: 'tomcat-jdbc'
}

compileJava {
	options.encoding = "UTF-8"
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章