2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 id "org.nosphere.apache.rat" version "0.3.0"
22 apply plugin: 'eclipse'
24 apply plugin: 'checkstyle'
25 apply plugin: 'jacoco'
26 apply plugin: 'findbugs'
27 apply plugin: 'maven-publish'
29 apply from: 'gradle/sqoop-version-gen.gradle'
30 apply from: 'gradle/sqoop-package.gradle'
32 group = 'org.apache.sqoopgradle'
34 sourceCompatibility = javaSourceCompatibilityVersion
39 url 'http://conjars.org/repo/'
46 srcDirs = ['src/java']
49 srcDirs = ['src/java']
54 srcDirs = ['src/test']
58 srcDirs = ['src/test', 'testdata/hcatalog/conf', 'conf']
64 srcDirs = ['src/test/aop']
67 srcDirs = ['src/test/aop']
73 common.extendsFrom(redist)
74 compile.extendsFrom(common)
77 compileJava.dependsOn(SqoopVersionFileGen)
81 force group: 'org.apache.avro', name: 'avro', version: avroVersion
82 force group: 'org.apache.avro', name: 'avro-mapred', version: avroVersion
83 force group: 'com.google.guava', name: 'guava', version: guavaVersion
84 force group: 'com.google.protobuf', name: 'protobuf-java', version: hiveProtobufVersion
86 exclude group: 'org.apache.hadoop', module: 'avro'
89 def sqoopThirdPartyLib = System.getProperty("sqoop.thirdparty.lib.dir")
90 def forkEveryDefault = Integer.valueOf(System.getProperty("forkEvery.default", "0"))
93 if (sqoopThirdPartyLib != null) runtime fileTree(dir: sqoopThirdPartyLib, include: '*.jar')
94 compile group: 'org.apache.hadoop', name: 'hadoop-aws', version: hadoopVersion
95 compile (group: 'org.apache.hadoop', name: 'hadoop-common', version: hadoopVersion) {
96 exclude group: "asm", module: "asm"
98 compile (group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: hadoopVersion) {
99 exclude group: "asm", module: "asm"
101 compile (group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-common', version: hadoopVersion) {
102 exclude group: "asm", module: "asm"
104 compile (group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-core', version: hadoopVersion) {
105 exclude group: "asm", module: "asm"
107 compile group: 'org.apache.hbase', name: 'hbase-hadoop-compat', version: hbaseVersion
109 aopCompile group: 'org.aspectj', name: 'aspectjtools', version: aspectjVersion
110 aopCompile group: 'org.aspectj', name: 'aspectjrt', version: aspectjVersion
111 aopCompile group: 'org.apache.hadoop', name: 'hadoop-common', version: hadoopVersion
113 common group: 'org.apache.accumulo', name: 'accumulo-core', version: accumuloVersion
114 common group: 'org.apache.accumulo', name: 'accumulo-minicluster', version: accumuloVersion
116 common group: 'org.eclipse.jetty', name: 'jetty-runner', version: jettyVersion
118 common group: 'org.apache.hbase', name: 'hbase-hadoop2-compat', version: hbaseVersion
119 common group: 'org.apache.hbase', name: 'hbase-server', version: hbaseVersion
120 common group: 'org.apache.hbase', name: 'hbase-client', version: hbaseVersion
121 common group: 'org.apache.hbase', name: 'hbase-common', version: hbaseVersion
122 common(group: 'org.apache.hive.hcatalog', name: 'hive-hcatalog-core', version: hcatalogVersion) {
123 exclude group: 'org.apache.avro', module: 'avro'
124 exclude group: 'org.apache.hive', module: 'hive-exec'
126 common(group: 'org.apache.hive', name: 'hive-exec', version: hcatalogVersion, classifier: 'core') {
127 exclude group : 'org.apache.calcite', module :'calcite-core'
129 // Kryo and calcite are dependencies of hive-exec:core
130 common group: 'com.esotericsoftware', name: 'kryo', version: kryoVersion
131 common group: 'org.apache.calcite', name: 'calcite-core', version: calciteVersion
132 common(group: 'org.apache.hive', name: 'hive-jdbc', version: hcatalogVersion) {
133 exclude group: 'org.apache.avro', module: 'avro'
134 exclude group: 'asm', module: 'asm'
136 common group: 'commons-cli', name: 'commons-cli', version: commonscliVersion
137 common group: 'commons-logging', name: 'commons-logging', version: commonsloggingVersion
138 common group: 'commons-net', name: 'commons-net', version: commonsnetVersion
139 common group: 'log4j', name: 'log4j', version: log4jVersion
140 common group: 'org.postgresql', name: 'postgresql', version: postgresqlVersion
141 common group: 'org.apache.parquet', name: 'parquet-hadoop-bundle', version: parquetVersion
143 testCompile group: 'com.h2database', name: 'h2', version: h2Version
144 testCompile group: 'org.apache.hbase', name: 'hbase-server', version: hbaseVersion, classifier: 'tests'
145 testCompile group: 'org.apache.hbase', name: 'hbase-hadoop2-compat', version: hbaseVersion, classifier: 'tests'
146 testCompile group: 'org.apache.hbase', name: 'hbase-hadoop-compat', version: hbaseVersion, classifier: 'tests'
147 testCompile (group: 'org.apache.hadoop', name: 'hadoop-minikdc', version: hadoopVersion) {
148 exclude group: 'org.apache.directory.api', module: 'api-ldap-schema-data'
150 testCompile group: 'junit', name: 'junit', version: junitVersion
151 testCompile group: 'org.assertj', name: 'assertj-core', version: assertjVersion
152 testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoallVersion
153 testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: systemRulesVersion
154 testCompile group: 'org.apache.zookeeper', name: 'zookeeper', version: zookeeperVersion, ext: 'jar'
157 task unitTest (type: Test) {
158 description 'Run unit tests which do not need proprietary JDBC driver'
160 includeCategories 'org.apache.sqoop.testcategories.sqooptest.UnitTest'
161 excludeCategories 'org.apache.sqoop.testcategories.thirdpartytest.ThirdPartyTest'
165 task integrationTest(type: Test) {
166 description 'Run integration tests which do not need a docker container or an external database/service'
168 includeCategories 'org.apache.sqoop.testcategories.sqooptest.IntegrationTest'
169 excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
170 excludeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
171 excludeCategories 'org.apache.sqoop.testcategories.thirdpartytest.ThirdPartyTest'
175 task thirdPartyTest (type: Test) {
176 description 'Run Third-party Tests - you need to specify -Dsqoop.thirdparty.lib.dir where the Third party driver ' +
177 'jars reside (relative to the project directory)'
179 includeCategories 'org.apache.sqoop.testcategories.thirdpartytest.ThirdPartyTest'
180 excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
181 excludeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
183 systemProperty "ms.datatype.test.data.file.export" ,"DatatypeTestData-export-lite.txt"
184 systemProperty "ms.datatype.test.data.file.import" ,"DatatypeTestData-import-lite.txt"
185 systemProperty "ms.datatype.test.data.file.delim" ,","
186 systemProperty "ms.datatype.test.hdfsprefix" ,"file:///"
190 description 'Run tests that do not need external JDBC driver and/or a docker container. ' +
191 'This is the same as running unitTest, integrationTest and kerberizedTest.'
193 includeCategories 'org.apache.sqoop.testcategories.sqooptest.UnitTest'
194 includeCategories 'org.apache.sqoop.testcategories.sqooptest.IntegrationTest'
195 excludeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
196 excludeCategories 'org.apache.sqoop.testcategories.thirdpartytest.ThirdPartyTest'
197 excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
201 task s3Test(type: Test) {
202 description 'Run S3 tests'
204 includeCategories 'org.apache.sqoop.testcategories.thirdpartytest.S3Test'
208 task allTest (type: Test){
209 description 'Run all Sqoop tests'
211 includeCategories 'org.apache.sqoop.testcategories.sqooptest.UnitTest'
212 includeCategories 'org.apache.sqoop.testcategories.sqooptest.IntegrationTest'
213 includeCategories 'org.apache.sqoop.testcategories.thirdpartytest.ThirdPartyTest'
214 excludeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
215 excludeCategories 'org.apache.sqoop.testcategories.sqooptest.ManualTest'
219 def testBuildDir = "$buildDir/test/"
220 def testBuildDirData ="$testBuildDir/data/"
223 project.mkdir(testBuildDirData)
226 tasks.withType(Test) {
228 events 'passed', 'skipped'
230 workingDir = testBuildDirData
231 project.mkdir(workingDir)
232 systemProperties(System.getProperties())
233 systemProperty "test.data.dir", "$projectDir/testdata"
234 systemProperty 'test.build.data', "$testBuildDir/data"
235 systemProperty "hadoop.root.logger", "DEBUG,console"
236 systemProperty "user.dir", workingDir
237 systemProperty "sqoop.src.dir", "$testBuildDir/data"
238 systemProperty "hadoop.tmp.dir", "$testBuildDir/hadoop"
239 systemProperty "fs.default.name", ""
240 systemProperty "hadoop.log.dir", "$testBuildDir/logs"
241 systemProperty "hive.home", "$projectDir/testdata/hive"
242 systemProperty "sqoop.throwOnError", ""
246 jvmArgs "-da:org.apache.hadoop.hive.thrift.HadoopThriftAuthBridge"
248 dependsOn buildFolder
251 excludes = ["**/SqoopVersion*"]
254 forkEvery forkEveryDefault
257 task kerberizedTest (type: Test){
258 description 'Run Kerberized Test'
259 // A Gradle test task with forkEvery 1 and includeCategories performs poorly because it starts a new JVM even for the filtered tests.
260 // To work around this performance problem we need to add every kerberized test in a separate include field here.
261 include '**/TestKerberosAuthenticator*'
262 include '**/HBaseKerberizedConnectivityTest*'
263 include '**/TestHiveMiniCluster*'
264 include '**/TestHiveServer2TextImport*'
266 includeCategories 'org.apache.sqoop.testcategories.KerberizedTest'
271 test.finalizedBy(kerberizedTest)
272 allTest.finalizedBy(kerberizedTest)
274 tasks.withType(Checkstyle) {
278 html.stylesheet resources.text.fromFile('config/checkstyle/checkstyle-noframes.xsl')
280 ignoreFailures = true
283 tasks.withType(FindBugs) {
288 ignoreFailures = false
297 toolVersion checkstyleVersion
301 description "Generates a coverage report of the unit test results under $buildDir/jacocoHtml/test/index.html"
302 executionData test, kerberizedTest
306 html.destination file("$buildDir/jacocoHtml/test")
310 task jacocoThirdPartyReport(type: JacocoReport){
311 description "Generates a coverage report of the thirdparty test results under $buildDir/jacocoHtml/3rd/index.html"
312 sourceSets sourceSets.main
313 executionData thirdPartyTest
317 html.destination file("$buildDir/jacocoHtml/3rd")
321 task jacocoCompositeReport(type: JacocoReport){
322 description "Generates a composite coverage report of test and thirdparty test results under $buildDir/jacocoHtml/index.html"
323 sourceSets sourceSets.main
324 executionData test, kerberizedTest, thirdPartyTest
328 html.destination file("$buildDir/jacocoHtml/")
333 source = sourceSets.main.allJava
334 include 'com/cloudera/sqoop/lib/**'
335 include 'org/apache/sqoop/lib/**'
336 destinationDir = reporting.file("${project.docsDir}/api")
339 task faultInjectionJar(type: Jar) {
340 description 'Create the test jar'
342 from sourceSets.aop.output
345 def archiveName = jar.baseName + "-" + jar.version
346 def binArtifactName = archiveName + ".bin__hadoop-" + hadoopVersion
347 def distDir = "$buildDir/$binArtifactName"
351 reportDir = project.file(buildDir)
352 excludes = ['**/docs/**', '**/testdata/**', '**/.idea/**', '**/test-dir/**', '**/.settings/**', '**/.gradle/**','**/gradle/**' ,'**/gradle/build/**', '*.iml', '*.iws', '*.ipr', 'derby.log', '**/gradlew**' ]
358 rat.dependsOn('packageDist')
360 def scripts = ['export', 'list-databases', 'metastore', 'create-hive-table', 'help',
361 'import-mainframe', 'list-tables', 'version',
362 'eval', 'import', 'job', 'merge',
363 'import-all-tables', 'codegen']
366 task runSqoopHelp(type: JavaExec, dependsOn: 'classes') {
367 main = 'org.apache.sqoop.Sqoop'
368 jvmArgs = ['-Dhadoop.security.log.file=./build/security-audit.log']
369 classpath = sourceSets.main.runtimeClasspath + configurations.runtime
371 standardOutput = new ByteArrayOutputStream()
373 standardOutput.toString()
378 task createAllStartScripts(dependsOn: 'runSqoopHelp' ) doLast{
379 // Placeholder task with validation
380 // We call Sqoop help to verify that all tasks that we create scripts for are present in Sqoop help and vice-versa
381 // We currently depend on the format of the help output to parse the relevant information out
382 def matcher = (tasks.runSqoopHelp.helpOut() =~/(?m)^\s\s([a-z-]+)\s+\w+/)
383 def matches = new String[matcher.getCount()]
384 for (def i=0; i < matcher.getCount(); i++) {
385 matches[i] = matcher[i][1]
387 if (matches.sort() != scripts.sort())
388 throw new GradleException('Error: script list in gradle build script and result of Sqoop help are not the same, but should be')
391 scripts.each() { scriptName ->
392 def t = tasks.create(name: scriptName + 'StartScript', type: CreateStartScripts) {
393 unixStartScriptGenerator.template = resources.text.fromFile('gradle/customUnixStartScript.txt')
394 windowsStartScriptGenerator.template = resources.text.fromFile('gradle/customWindowsStartScript.txt')
395 outputDir = file("$buildDir/bin")
396 applicationName = scriptName
397 mainClassName = 'com.cloudera.sqoop.Sqoop'
398 classpath = project.configurations.runtime
400 file("$buildDir/bin/"+ scriptName).renameTo(file("$buildDir/bin/"+"sqoop-"+scriptName))
401 file("$buildDir/bin/"+ scriptName +".bat").renameTo(file("$buildDir/bin/"+"sqoop-"+scriptName+".bat"))
404 t.dependsOn('compileJava')
405 createAllStartScripts.dependsOn(t)
408 task checkVersion doLast {
409 if (version.contains('SNAPSHOT'))
410 throw new GradleException('Error: cannot release a snapshot. Set -Pversion')
413 task release(dependsOn: ['checkVersion', 'tar', 'rat']) {
415 println 'Release complete'
416 println "Binary tar: $buildDir/$binArtifactName-${version}.tar.gz"
417 println "Documentation: $buildDir/docs"
418 println "Release notes: $buildDir/docs/sqoop-$version" + ".releasenotes.html"
419 println "Release audit report: $buildDir/index.html"
423 task relnotes(type: Exec) {
424 workingDir 'src/scripts'
425 if (!version.contains('SNAPSHOT')) {
426 commandLine "python", "relnotes.py", "$buildDir/docs", "$projectDir", "$oldHash\\..HEAD", "$version", "$oldVersion"
428 commandLine "true" //noop
429 println "Will not run releasenotes for SNAPSHOT version."
433 task realDocs(type: Exec, dependsOn: ['relnotes', 'javadoc']) {
434 workingDir projectDir
435 commandLine "make", "-C", "$projectDir/src/docs", "BUILDROOT=$buildDir", "VERSION=$version"
438 task docs(dependsOn: ['realDocs', 'relnotes', 'javadoc']) {
441 def $mvnRepo = System.getProperty("mvnRepo", "snapshots")
446 name "cloudera." + $mvnRepo + ".repo"
447 url "https://repository.cloudera.com/content/repositories/"+$mvnRepo
457 sqoop(MavenPublication) {
465 sqoopTest(MavenPublication) {
468 artifactId 'sqoop-test'
470 artifact sourceTestJar
472 def dependencies = asNode().appendNode('dependencies')
473 configurations.testRuntime.getResolvedConfiguration().getFirstLevelModuleDependencies().each {
474 def dependency = dependencies.appendNode('dependency')
475 dependency.appendNode('groupId', it.moduleGroup)
476 dependency.appendNode('artifactId', it.moduleName)
477 dependency.appendNode('version', it.moduleVersion)
485 gradleVersion = '4.9'