Hello world !
I want to write a task in gradle but it doesn’t work.
Thank your for helping !
version used: 6.8.1
file build.gradle
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.7.1/userguide/building_java_projects.html
*/
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.hibernate:hibernate-core:5.+'
classpath 'com.h2database:h2:1.+'
classpath 'com.github.javafaker:javafaker:1.0.+'
}
}
plugins {
id 'application'
id 'java'
id 'java-test-fixtures'
}
group = "com.github.user"
version = '1.0.0'
repositories {
// Use JCenter for resolving dependencies.
// This is repo will not be resolved after February 2022
jcenter()
// then
mavenCentral()
// others
maven {
// This is used to get package from git repository (example: github)
url "https://jitpack.io"
}
}
dependencies {
// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
implementation 'org.hibernate:hibernate-core:5.+'
// https://mvnrepository.com/artifact/com.h2database/h2
implementation 'com.h2database:h2:1.+'
/* Use sqlite if you do not want use H2 database */
// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
implementation 'org.xerial:sqlite-jdbc:3.+'
//https://github.com/gwenn/sqlite-dialect
implementation 'com.github.gwenn:sqlite-dialect:master'
// https://mvnrepository.com/artifact/javax.validation/validation-api
implementation 'javax.validation:validation-api:2.0.1.Final'
// https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api
implementation 'javax.persistence:javax.persistence-api:2.2'
// https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api
implementation 'jakarta.validation:jakarta.validation-api:3.0.0'
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
implementation 'org.yaml:snakeyaml:1.29'
// https://mvnrepository.com/artifact/commons-io/commons-io
implementation 'commons-io:commons-io:2.8.+'
/* tests */
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.+'
// https://mvnrepository.com/artifact/com.github.javafaker/javafaker
testImplementation 'com.github.javafaker:javafaker:1.0.+'
/* For GUI tests */
// https://mvnrepository.com/artifact/org.assertj/assertj-swing-junit
testImplementation 'org.assertj:assertj-swing-junit:3.17.+'
/* tests fixtures */
// https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api
testFixturesApi 'javax.persistence:javax.persistence-api:2.2'
testFixturesApi 'com.github.javafaker:javafaker:1.0.+'
// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.+'
}
application {
// Define the main class for the application.
mainClass = 'com.github.user.hangman.Main'
}
tasks.withType(JavaCompile) {
//options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
tasks.named('test') {
// Use junit platform for unit tests.
useJUnitPlatform()
}
jar {
manifest {
attributes "Main-Class": "com.github.user.Main"
}
from {
archiveBaseName = "hangman"
archiveClassifier = "all"
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.compileClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.named('jar') {
manifest {
attributes(
'Implementation-Title': 'hangman',
'Implementation-Version': project.version
)
}
}
test {
useJUnitPlatform()
/* uncomment this block if you need it
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
showStandardStreams = true
}
*/
}
tasks.register("hello") {
/*
* I want to call this java Faker class but does not work
* I want to call WordRepository also but does not work
* #WordRepository is under hangman/app/src/main/java/com/github/takeonme/repository/WordRepository
*/
Faker f = new Faker()
new WordRepository()
}
file settings.gradle
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/6.7.1/userguide/multi_project_builds.html
*/
rootProject.name = 'hangman'
include('app')