2 Ekim 2022 Pazar

unbroken-dome plugin - Integration Test İçindir

Şöyle yaparız
id 'org.unbroken-dome.test-sets' version '4.0.0'

testSets {
   integrationTest
}
Çalıştırmak için şöyle yaparız
./gradlew integrationTest




28 Eylül 2022 Çarşamba

run Task

Örnek
Şöyle yaparız
gradle run

sonar plugin

Plugin Tanımlama
Şöyle yaparız
plugins { ... id "org.sonarqube" version "3.3" }
Plugin Properties
Property değeleri gradle.properties veya build.gradle dosyalarında tanımlanabilir.

1. gradle.properties
Şöyle yaparız
systemProp.sonar.host.url=http://localhost:9000 systemProp.sonar.login=<sonar-key>
2. build.gradle
Eğer Sonar master'dan farklı branch'lere bakabilen paralı sürümse şöyle yaparız
sonarqube { properties { property "sonar.branch.name", System.getenv('BRANCH_NAME') } }
Örnek
Şöyle yaparız
sonarqube { properties { property "sonar.projectKey", "luizgustavocosta_16-bits-zero-to-hero" property "sonar.organization", "luizgustavocosta" property "sonar.host.url", "https://sonarcloud.io" } }
Plugin Targetları
sonarqube target
Static code analysis işlemini başlatır. Projeyi derlemek için şöyle yaparız
./gradlew clean build
Test sonuçlarını Sonar'a göndermek için şöyle yaparız
./gradlew sonarqube -Dsonar.projectKey=spring-boot-simple
-Dsonar.host.url=http://localhost:9000
-Dsonar.login=da55e6a2a39868ae22bd77aaf48e61c26b19d8b7

9 Haziran 2022 Perşembe

distribution plugin - Projeyi Zip veya Tar'lar

Giriş
.sh, .bash, Word belgesi gibi şeyleri zip'leyerek dağıtmak için kullanılabilir

Örnek
Şöyle yaparız
plugins {
    id 'distribution'
}

distributions {
  main {
    contents {
      from(projectDir) {
        include 'scripts/**'
        include 'doc/**'
      }
    }
  }
}

jar.enabled = false
distTar.enabled = false
"gradle build" komutunu çalıştırınca "build\distributions" dizini altında proje ismine sahip bir zip oluşur

30 Mayıs 2022 Pazartesi

checkstyle plugin

Giriş
Bu eklentinin ana sayfası burada. Şöyle yaparız
plugins {
  // Apply the java-library plugin for API and implementation separation.
  id 'java-library'
  id 'checkstyle' 
}
Modulün bulunduğu yerde şöyle bir dosya oluşturulur
config\checkstyle\checkstyle.xml
Sonra şöyle yaparız
checkstyle {
  configFile = file("${rootDir}/config/checkstyle/checkstyle.xml") 
}
checkstyleMain {
  source ='src/main/java'
}
checkstyleTest {
  source ='src/test/java'
}
Daha sonra şöyle yaparız. 
gradle check
Açıklaması şöyle
The Checkstyle plugin adds the following dependencies to tasks defined by the Java plugin.

check
Depends on: All Checkstyle tasks, including checkstyleMain and checkstyleTest.

veya şöyle yaparız
gradle build





27 Mayıs 2022 Cuma

eclipse plugin

Giriş
Açıklaması şöyle. Yani Eclipse tarafından kullanılan ".project" dosyasını üretir
The Eclipse plugins generate files that are used by the Eclipse IDE, thus making it possible to import the project into Eclipse (File - Import…​ - Existing Projects into Workspace).
Örnek
Şöyle yaparız    
plugins {
  id 'eclipse'
}

eclipse {
  classpath {
    downloadJavadoc = false
    downloadSources = true
  }
}

7 Nisan 2022 Perşembe

Custom Task Örnekleri

Örnek
Elimizde şöyle bir xml vardı
<dependencyManagement>
  <dependencies>
    <dependency>
      ...
    </dependency>
  <dependencies>
<dependencyManagement>

<dependencyManagement>
  <dependencies>
    <dependency>
      ...
    </dependency>
  <dependencies>
<dependencyManagement>
Bu ikisini birleştirmek için şöyle yaptım. Aslında kod buradan geldi
import java.util.regex.Matcher
task fixPom { doLast { File file = new File("$buildDir/publications/maven_1/pom-default.xml") if (!file.exists()) { return; } println("Fixing pom for " + file.getPath()) def text = file.text def pattern = "(?s)(<dependencyManagement>.+?<dependencies>)(.+?)(</dependencies>.+?</dependencyManagement>)" Matcher matcher = text =~ pattern if (matcher.find()) { //Remove the first <dependencyManagement> tag text = text.replaceFirst(pattern, "") //Get all all <dependency> tags def firstDeps = matcher.group(2) //Get (<dependencyManagement>.+?<dependencies>)(.+?) part //add new dependencies and close the tag text = text.replaceFirst(pattern, '$1$2' + firstDeps + '$3') } file.write(text) } }
Bu yeni task'ı şöyle kullandım
generatePomPropertiesFile.dependsOn("fixPom")
Çünkü asemble için sıra şöyleydi
ompileJava
processResources
classes
createPropertiesFileForJar
generatePomFileForMaven_1Publication

fixPom //Burada araya girdim

generatePomPropertiesFile
writeManifestProperties
jar
createPropertiesFileForSourcesJar
sourcesJar
assemble




Gradle Daemon Nedir?

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...