Giriş
Açıklaması şöyle. Base plugin ile geliyor
assemble - Assembles the outputs of this project.
Testleri çalıştırmadığı için
komutuna tercih edilebilirgradle build -x test
assemble - Assembles the outputs of this project.
komutuna tercih edilebilirgradle build -x test
Gradle provides several options that make it easy to configure the Java process that will be used to execute your build. While it’s possible to configure these in your local environment via GRADLE_OPTS or JAVA_OPTS, it is useful to be able to store certain settings like JVM memory configuration and Java home location in version control so that an entire team can work with a consistent environment. To do so, place these settings into a gradle.properties file committed to your version control system.
Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settings for build performance. This does not affect the JVM settings for the Gradle client VM. The default is -Xmx512m "-XX:MaxMetaspaceSize=256m".
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
> Task :tiTree:build (org.gradle.api.DefaultTask)+--- :assemble (org.gradle.api.DefaultTask)| `--- :jar (org.gradle.api.tasks.bundling.Jar)| +--- :classes (org.gradle.api.DefaultTask)| | +--- :compileGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | | `--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)| `--- :writeManifestProperties (nebula.plugin.info.reporting.InfoPropertiesFile)`--- :check (org.gradle.api.DefaultTask)+--- :downloadLicenses (nl.javadude.gradle.plugins.license.DownloadLicenses)+--- :license (org.gradle.api.DefaultTask)| +--- :licenseMain (com.hierynomus.gradle.license.tasks.LicenseCheck)| `--- :licenseTest (com.hierynomus.gradle.license.tasks.LicenseCheck)`--- :test (org.gradle.api.tasks.testing.Test)+--- :classes (org.gradle.api.DefaultTask)| +--- :compileGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | `--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)+--- :testClasses (org.gradle.api.DefaultTask)| +--- :compileTestGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | +--- :classes (org.gradle.api.DefaultTask)| | | +--- :compileGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | | | `--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | | +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | | `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)| | `--- :compileTestJava (org.gradle.api.tasks.compile.JavaCompile)| | `--- :classes (org.gradle.api.DefaultTask)| | +--- :compileGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | | `--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)| +--- :compileTestJava (org.gradle.api.tasks.compile.JavaCompile)| | `--- :classes (org.gradle.api.DefaultTask)| | +--- :compileGroovy (org.gradle.api.tasks.compile.GroovyCompile)| | | `--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)| | `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)| `--- :processTestResources (org.gradle.language.jvm.tasks.ProcessResources)`--- :buildDashboard (finalizer) (org.gradle.api.reporting.GenerateBuildDashboard)
The plugins block is the newer method of applying plugins, and they must be available in the Gradle plugin repository.
...The new plugins method does not work in multi-project configurations (subprojects, allprojects), but will work on the build configuration for each child project.
buildscript { repositories { // define repositories for build script dependencies } dependencies { // define build script dependencies (a.k.a. plugins) } } repositories { // define repositories for regular project dependencies } dependencies { // define regular project dependencies }
buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE" } } apply plugin: "org.springframework.boot"
Keep in mind, that applying a plugin using the plugins DSL (plugins {...}) does not work for your private plugins or company plugins which are not published to the official Gradle plugin repo.
buildscript { dependencies { classpath group: '...', name: '...', version: '...' classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE" ... } }
plugins {id «plugin id» version «plugin version» [apply «false»]}
plugins { id 'com.github.johnrengelman.shadow' version '7.1.1' id 'java' }
plugins { id 'com.github.johnrengelman.shadow' version '6.1.0' }
buildscript { repositories { gradlePluginPortal() } dependencies { classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.1.1' } } apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java'
gradle shadowJar --stacktrace --warning-mode all
foo-1.0.1-SHAPSHOT-all.jar
apply plugin:"com.github.johnrengelman.shadow" shadowJar { mergeServiceFiles() } $ ./gradlew shadowJar $java -jar build/libs/math-function-0.1-all.jar
dependencies { compile gradleApi() compile localGroovy() compile "com.github.jengelman.gradle.plugins:shadow:6.0.0" }
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext import shadow.org.apache.tools.zip.ZipOutputStream import org.gradle.api.file.FileTreeElement import org.slf4j.LoggerFactory import org.slf4j.Logger class ExcludeDuplicates implements Transformer { Logger logger = LoggerFactory.getLogger(ExcludeDuplicates.class) Map<String, Boolean> map = new HashMap<>() boolean canTransformResource(FileTreeElement element) { def path = element.relativePath.pathString logger.debug('Relative Path from element ' + path) if (element.file != null) { logger.debug('Absolute from sources ' + element.file.absolutePath) } else { logger.debug('Element "file" must not be null!') } boolean visited = map.getOrDefault(path, false) if (!visited) { logger.debug('First time visited') map.put(path, true) } return visited } void transform(TransformerContext context) {} boolean hasTransformedResource() { true } void modifyOutputStream(ZipOutputStream jos, boolean preserveFileTimestamps) {} }
shadowJar { classifier = null configurations = [project.configurations.shadow] transform(new ExcludeDuplicates()) }
Holds runtime dependencies that are not merged
// Output to build/libs/shadow.jar shadowJar { archiveBaseName.set('shadow') archiveClassifier.set('') archiveVersion.set('') }
shadowJar { duplicatesStrategy = DuplicatesStrategy.FAIL }
shadowJar { baseName = project.name classifier = '' archiveVersion = '' exclude "META-INF/*.SF" exclude "META-INF/*.DSA" exclude "META-INF/*.RSA" }
When you apply the io.spring.dependency-management plugin, Spring Boot’s plugin will automatically import the spring-boot-dependencies bom from the version of Spring Boot that you are using. This provides a similar dependency management experience to the one that’s enjoyed by Maven users. For example, it allows you to omit version numbers when declaring dependencies that are managed in the bom. To make use of this functionality, declare dependencies in the usual way but omit the version number:
plugins {
id "org.springframework.boot" version "2.1.5.RELEASE"
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
plugins {
id "io.spring.dependency-management" version <<version>>
}
dependencyManagement {
imports {
// The plugin already brings spring-boot-dependencies BOM,
// We can also add other BOMs like:
mavenBom 'another:dependency-bom:2.0.0'
}
}
dependencies {
// Then, now we can simply declare the dependencies we need
// without having to worry about their versions
implementation 'org.apache.kafka:connect-api'
implementation 'com.rabbitmq:amqp-client'
}
plugins {id 'java'}group = 'com.mybot'version = '0.0.1-SNAPSHOT'sourceCompatibility = '11'
No more release or sourceCompatibility tweaks, no more wiki pages describing which JDK you should install for the build to work.
- All Java compilation tasks will use Java 11 to build. That means code in the main and test source sets, but also Java code in any custom source set you add, will be built with the configured Java version.
- All tests tasks, including the default test task and any additional custom Test task, will use Java 11 to run the tests.
- The javadoc task will use Java 11 to build the documentation.
gradle -q javaToolchains + Options | Auto-detection: Enabled | Auto-download: Enabled + Eclipse Adoptium JDK 17.0.2+8 | Location: C:\Users\user\.gradle\jdks\jdk-17.0.2+8 | Language Version: 17 | Vendor: Eclipse Adoptium | Is JDK: true | Detected by: Auto-provisioned by Gradle + Oracle JDK 17.0.1+12-LTS-39 | Location: D:\Kurulumlar\JDK\jdk-17_windows-x64_bin\jdk-17.0.1 | Language Version: 17 | Vendor: Oracle | Is JDK: true | Detected by: Current JVM + Temurin JDK 1.8.0_322-b06 | Location: C:\Users\user\.gradle\jdks\jdk8u322-b06 | Language Version: 8 | Vendor: Temurin | Is JDK: true | Detected by: Auto-provisioned by Gradle
$ gradle -q javaToolchains + Options | Auto-detection: Enabled | Auto-download: Enabled + OpenJDK 1.8.0_292 | Location: /usr/lib/jvm/java-8-openjdk | Language Version: 8 | Vendor: Oracle | Is JDK: true | Detected by: Current JVM + OpenJDK 11.0.11 | Location: /usr/lib/jvm/java-11-openjdk | Language Version: 11 | Vendor: Oracle | Is JDK: true | Detected by: Common Linux Locations
./gradlew --no-daemon -q javaToolchains + Options | Auto-detection: Enabled | Auto-download: Enabled + OpenJDK 1.7.0_261-mockbuild_2020_04_29_08_59-b00 | Location: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64 | Language Version: 7 | Vendor: Oracle | Is JDK: true | Detected by: Common Linux Locations + OpenJDK JRE 1.7.0_261-mockbuild_2020_04_29_08_59-b00 | Location: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64/jre | Language Version: 7 | Vendor: Oracle | Is JDK: false | Detected by: Common Linux Locations + Red Hat, Inc. JDK 1.8.0_292-b10 | Location: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 | Language Version: 8 | Vendor: Red Hat, Inc. | Is JDK: true | Detected by: Current JVM + Red Hat, Inc. JDK 11.0.11+9-LTS | Location: /usr/lib/jvm/java-11-openjdk-11.0.11.0.9-1.el7_9.x86_64 | Language Version: 11 | Vendor: Red Hat, Inc. | Is JDK: true | Detected by: Common Linux Locations + Red Hat, Inc. JRE 1.8.0_292-b10 | Location: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre | Language Version: 8 | Vendor: Red Hat, Inc. | Is JDK: false | Detected by: Common Linux Locations
java { toolchain { languageVersion = JavaLanguageVersion.of(8) } } tasks.withType(JavaCompile) { options.release.set(8) //Buna gerek yok ama olmadı }
java { toolchain { languageVersion = JavaLanguageVersion.of(17) } }
Unable to download toolchain matching these requirements: {languageVersion=17, vendor=any, implementation=vendor-specific} > Could not GET 'https://api.adoptopenjdk.net/v3/binary/latest/17/ga/linux/x64/jdk/hotspot/normal/adoptopenjdk'. Received status code 403 from server: Forbidden
java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } tasks.withType(JavaCompile) { options.release.set(17) options.compilerArgs = ['--add-modules=jdk.incubator.foreign', '--enable-preview', '-Xlint:preview'] } // dependencies, etc.
The Application Plugin also automatically includes the Distribution Plugin. The Distribution Plugin creates two archives: TAR and ZIP. Their contents are identical and include the project jar, all dependency jars, and two scripts: Bash and .bat-file. Then, distributing our application is no problem at all: We can use our-project/build/distributions/our-project-1.0.1.zip, unpack it, and run the executable script:$ unzip our-project-1.0.1.zip$ ./our-project-1.0.1/bin/our-project-1.0.1
You can run gradle installDist to create an image of the application in build/install/projectName. You can run gradle distZip to create a ZIP containing the distribution, gradle distTar to create an application TAR or gradle assemble to build both.
binfoofoo.batlibÇeşitli jar dosyaları
plugins {id 'application'}application {mainClassName = 'com.foo.FooMain'applicationDefaultJvmArgs = ['-Doracle.jdbc.autoCommitSpecCompliant=false']distTar.enabled = false}distributions {main {contents {into('bin') {from 'src/main/resources'include 'Foo.ico'include 'setup.vbs'}}}}
distributions { main { contents { from 'bringup-files' from (project(':licensingEngine:licenseUploader').distZip) { include project(':licensingEngine:licenseUploader').distZip.archiveFileName into 'bring_up_files/license' } } } }
application {mainClass = 'org.gradle.sample.Main' }
The usage of the compile and runtime configurations in the Java ecosystem plugins has been discouraged since Gradle 3.4.
...
Other sources sets create similar configurations (e.g. testCompile and testRuntime for the test source set), should not be used either.
compileOnly is the replacement — the equivalent configuration that is being deprecated is provided
api (same as compile it also leaks(exposes) dependencies to the consumer’s compile-classpath)
plugins {id 'java-library'}
3. runtimeOnlyDependencies whose API is required at compile time but whose implementation is to be provided by a consuming library, application or runtime environment.
compile(Deprecated)
Compile time dependencies. Superseded by implementation.
dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' }
dependencies { ... developmentOnly 'org.springframework.boot:spring-boot-devtools' }
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
Earlier we had a configuration called compile(Deprecated) which leak dependencies to the consumer’s compile-classpath which can cause dependency pollution (means unnecessary recompile and accidental use of transitive dependency).
dependencies {implementation 'org.springframework.boot:spring-boot-starter-web:2.2.5.RELEASE'}
gradlew dependencies --configuration=testRuntimeClasspath | find "log4j"
------------------------------------------------------------ Root project ------------------------------------------------------------ testRuntimeClasspath - Runtime classpath of source set 'test'. +--- org.apache.logging.log4j:log4j-api -> 2.17.1 +--- org.apache.logging.log4j:log4j-core -> 2.17.1 | \--- org.apache.logging.log4j:log4j-api:2.17.1 +--- com.github.stefanbirkner:system-rules -> 1.17.0 | \--- junit:junit-dep:[4.9,) -> 4.11 | \--- junit:junit:4.11 -> 4.13.2 | \--- org.hamcrest:hamcrest-core:1.3 +--- org.junit.jupiter:junit-jupiter-api -> 5.8.1 | +--- org.junit:junit-bom:5.8.1 | | +--- org.junit.jupiter:junit-jupiter-api:5.8.1 (c) | | +--- org.junit.jupiter:junit-jupiter-engine:5.8.1 (c) | | +--- org.junit.platform:junit-platform-commons:1.8.1 (c) | | +--- org.junit.platform:junit-platform-engine:1.8.1 (c) | | \--- org.junit.vintage:junit-vintage-engine:5.8.1 (c) | +--- org.opentest4j:opentest4j:1.2.0 | \--- org.junit.platform:junit-platform-commons:1.8.1 | \--- org.junit:junit-bom:5.8.1 (*) +--- org.junit.jupiter:junit-jupiter-engine -> 5.8.1 | +--- org.junit:junit-bom:5.8.1 (*) | +--- org.junit.platform:junit-platform-engine:1.8.1 | | +--- org.junit:junit-bom:5.8.1 (*) | | +--- org.opentest4j:opentest4j:1.2.0 | | \--- org.junit.platform:junit-platform-commons:1.8.1 (*) | \--- org.junit.jupiter:junit-jupiter-api:5.8.1 (*) \--- org.junit.vintage:junit-vintage-engine -> 5.8.1 +--- org.junit:junit-bom:5.8.1 (*) +--- org.junit.platform:junit-platform-engine:1.8.1 (*) \--- junit:junit:4.13.2 (*)
gradle mymodule:dependencies
apply from: "${rootDir}/gradle/license.gradle"
plugins {id "com.github.hierynomus.license" version "0.15.0"}
//A license extension is added to the project, which can be used to configure all //LicenseCheck and LicenseFormat license { header = file("${rootDir}/config/LICENSE.template") //şablon dosya yolu //variable substitution
ext.year = Calendar.getInstance().get(Calendar.YEAR) ext.name = 'Foo Inc.' ignoreFailures = true //Prevent tasks from stopping the build, defaults to false
mapping { java = 'SLASHSTAR_STYLE' //Üretilen başlık Javadoc gibidir } }
Copyright (c) ${name} and/or its affiliates, ${year} All Rights Reserved. The software contained on this media is proprietary to and embodies the confidential technology of the copyright holder. Possession, use, duplication or dissemination of the software and media is authorized only pursuant to a valid written license from the copyright holder. This copyright notice must appear in all copies of this software.
This task checks all the configured source files to validate whether the correct header has been applied.
This task formats all the configured source files to add a header to them if no header has been applied yet.
tasks/license/licenseFormat
gradle licenseFormatMain
plugins {id "com.github.hierynomus.license-report" version "0.15.0" }
generates reports on your runtime dependencies
build/reports/license/
//generates reports on your runtime dependencies downloadLicenses { ignoreFatalParseErrors = true includeProjectDependencies = true //a pre-defined mapping of a dependency to a license; useful if the //external repositories do not have license information available
licenses = [ (group('com.foo')) : license('Foo License'), (group('com.colak.myapp')) : license('My License') ]
//a List of dependencies that are to be excluded from reporting
excludeDependencies = [ 'org.wildfly.*', 'org.jboss.*', 'com.foo.bar.*', 'javax.*' ] //Gradle dependency configuration to report on (defaults to "runtime"). dependencyConfiguration = 'compile' }
//You will have to specify for which configuration dependencies should be resolved. //Following are resolvable by default: //- compileClasspath // - runtimeClasspath downloadLicenses { includeProjectDependencies = true dependencyConfiguration = 'runtimeClasspath' // or // dependencyConfiguration = 'compileClasspath' }
Gradle was first released in 2008. Building on Maven’s concepts, it was introduced as Maven’s successor. Rather than using Maven’s XML-based project configuration, it introduced a domain-specific language (DSL) based on the Groovy and Kotlin programming languages. Gradle supports Maven and Ivy repositories for declaring project configurations. It was designed with multi-project builds in mind.
build.gradlegradlewrappergradle-wrapper.jargradle-wrapper.propertiesgradlewgradlew.batsettings.gradlesrcmainjavaApp.javatestjavaAppTest.java
Notice you’re using a local script, ./gradlew and not gradle itself. That’s the Gradle wrapper. It has a couple of nice advantages. First, it locks the Gradle version so that the build script is guaranteed to work with the Gradle version running it. Second, it means you don’t have to install Gradle locally.Windows'ta farklı bir JDK ile çalıştırmak için şöyle yaparız
.\gradlew assemble -D"org.gradle.java.hom"e="D:\Kurulumlar\amazon1.8"
build- generatePomPropertiesFile- libs- manifest- publications- resources- tmp
C:\Users\acelya\.gradle\caches\modules-2\files-2.1
plugins {id 'java'id 'jacoco'id 'pmd'id 'checkstyle'}group 'com.datamify'version '1.0-SNAPSHOT'repositories {mavenCentral()}pmd {consoleOutput = truetoolVersion = "6.21.0"rulesMinimumPriority = 5}checkstyle {toolVersion '8.40'ignoreFailures true}tasks.withType(Checkstyle) {reports {xml.required = truehtml.required = true}}
apply from: "${rootDir}/gradle/jacoco.gradle"
apply plugin: 'jacoco' jacoco { toolVersion = '0.8.7' } jacocoTestReport { reports { xml.enabled false csv.enabled false html.enabled true } }
If the Java plugin is also applied to your project, a new task named jacocoTestReport is created. By default, a HTML report is generated at $buildDir/reports/jacoco/test.
While tests should be executed before generation of the report, the jacocoTestReport task does not depend on the test task.
gradlew clean test jacocoTestReport
test { finalizedBy jacocoTestReport // report is always generated after tests run } jacocoTestReport { dependsOn test // tests are required to run before generating the report }
plugins { id 'jacoco' }
jacoco { toolVersion = "0.8.7" }
test { finalizedBy jacocoTestReport }
jacoco {
toolVersion = '0.8.7'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
}
}
jacocoTestReport {
reports {
xml.enabled true
}
}
plugins {
id "org.sonarqube" version "$sonarQubeVersion"
id "jacoco"
}
jacoco {
toolVersion = "0.8.6"
reportsDir = file("$buildDir/jacocoreports")
}
jacocoTestReport {
reports {
xml.enabled true
}
}
test.finalizedBy jacocoTestReport
sonarqube {
properties {
property 'sonar.coverage.exclusions', '**/dto/**,**/util/**,**/ResponseExceptionHandler.java,,**/Application.java'
property 'sonar.coverage.jacoco.xmlReportPaths', "$buildDir/jacocoreports/test/jacocoTestReport.xml"
}
}
jacocoTestReport { dependsOn test reports { xml.required = true csv.required = true html.required = true } }
jacocoTestCoverageVerification {violationRules {rule {limit {minimum = 0.8}}rule {limit {counter = 'BRANCH'value = 'COVEREDRATIO'minimum = 0.8}}}}
check.dependsOn jacocoTestCoverageVerification
plugins {id 'java'id 'jacoco'}dependencies {testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'}test {useJUnitPlatform()finalizedBy jacocoTestReport}jacocoTestReport {dependsOn testreports {html.required = true}}jacocoTestCoverageVerification {violationRules {rule {limit {minimum = 0.8}}}}check.dependsOn jacocoTestCoverageVerification
Giriş Açıklaması şöyle . Gradle Daemon arka planda çalışır. Çünkü Gradle'ı ayağa kaldırmak ve ilklendirmek çok uzun sürüyor. Gradle ru...