我是新來的gradle,並試圖將我的POM轉換爲gradle.build。我已經轉換了依賴部分,現在轉換插件部分。我在我的POM轉換maven jar和複製資源插件gradle
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>
junit, org.apache.logging.log4j, org.springframework, aopalliance, org.springframework.data, javax.inject,
org.hibernate, javax.el, com.microsoft.sqlserver, org.apache.commons, com.jcraft, com.sun.mail,
org.apache.velocity, commons-lang, commons-logging, commons-collections, org.jboss.logging,
org.jboss, org.javassist, dom4j, javax.transaction
</includeGroupIds>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.vm</exclude>
<exclude>**/*.txt</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>dependency-jars/</classpathPrefix>
<mainClass>com.softech.ls360.integration.BatchImport</mainClass>
</manifest>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.vm</include>
<include>**/*.txt</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
下面當我跑這POM然後我得到的結構是這樣
現在我用下面的試了一下用渣滓罐任務
apply plugin: 'application' // implicitly apply java and distribution plugin
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = sourceCompatibility
mainClassName = "com.softech.ls360.integration.BatchImport"
version = '1.0'
ext {
log4jGroupId = "org.apache.logging.log4j"
springFrameworkGroupId = "org.springframework"
springFrameworkVersion = "4.2.4.RELEASE"
junitVersion = "4.12"
....
}
dependencies {
compile group: log4jGroupId, name: 'log4j-api', version: log4jVersion
....
runtime group: 'org.jboss.logging', name: 'jboss-logging', version: jbossLoggingVersion
....
testCompile group: 'junit', name: 'junit', version: junitVersion
}
jar {
// Keep jar clean:
exclude '**/*.properties', '**/*.xml', '**/*.vm', '**/*.txt'
//from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes ('Implementation-Version': version,
'Main-Class': "$mainClassName",
'Class-Path': "conf/" + " " + configurations.runtime.files.collect {"dependency-jars/$it.name" }.join(' ')
)
}
}
然後我得到了下面的jar
它是產生在罐子正確的類路徑。但build/libs/
文件夾只包含jar,其中沒有dependency-jars
和conf
文件夾。我如何創建這些文件夾,所以當我運行任務jar時,它會在build/libs/
文件夾中創建jar,同時創建dependency-jars
文件夾以及其中的所有jar文件。並且conf
文件夾中的build/libs
,與所有.propeties, .xml, .vm, .txt
文件從src/main/resources/
文件夾中。
謝謝