From c38a5eeb80cc2bd9492ee8ce59cfd431af8f42a6 Mon Sep 17 00:00:00 2001 From: KP9lKk Date: Mon, 13 Jan 2025 14:44:19 +0300 Subject: [PATCH] git init --- .gitignore | 45 +++++++++++++++++++ .idea/.gitignore | 3 ++ README.md | 23 ++++++++++ app/build.gradle.kts | 19 ++++++++ app/src/main/kotlin/main.kt | 23 ++++++++++ app/src/main/kotlin/model/UserAuthorize.kt | 10 +++++ buildSrc/build.gradle.kts | 15 +++++++ buildSrc/settings.gradle.kts | 17 +++++++ .../src/main/kotlin/kotlin-jvm.gradle.kts | 29 ++++++++++++ gradle.properties | 7 +++ gradle/libs.versions.toml | 22 +++++++++ settings.gradle.kts | 25 +++++++++++ utils/build.gradle.kts | 13 ++++++ 13 files changed, 251 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 README.md create mode 100644 app/build.gradle.kts create mode 100644 app/src/main/kotlin/main.kt create mode 100644 app/src/main/kotlin/model/UserAuthorize.kt create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/libs.versions.toml create mode 100644 settings.gradle.kts create mode 100644 utils/build.gradle.kts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1dff0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Kotlin ### +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/README.md b/README.md new file mode 100644 index 0000000..494e03d --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# AuthApplication + +This project uses [Gradle](https://gradle.org/). +To build and run the application, use the *Gradle* tool window by clicking the Gradle icon in the right-hand toolbar, +or run it directly from the terminal: + +* Run `./gradlew run` to build and run the application. +* Run `./gradlew build` to only build the application. +* Run `./gradlew check` to run all checks, including tests. +* Run `./gradlew clean` to clean all build outputs. + +Note the usage of the Gradle Wrapper (`./gradlew`). +This is the suggested way to use Gradle in production projects. + +[Learn more about the Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). + +[Learn more about Gradle tasks](https://docs.gradle.org/current/userguide/command_line_interface.html#common_tasks). + +This project follows the suggested multi-module setup and consists of the `app` and `utils` subprojects. +The shared build logic was extracted to a convention plugin located in `buildSrc`. + +This project uses a version catalog (see `gradle/libs.versions.toml`) to declare and version dependencies +and both a build cache and a configuration cache (see `gradle.properties`). \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..00a91aa --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + // Apply the shared build logic from a convention plugin. + // The shared code is located in `buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts`. + id("buildsrc.convention.kotlin-jvm") + + // Apply the Application plugin to add support for building an executable JVM application. + application +} + +dependencies { + // Project "app" depends on project "utils". (Project paths are separated with ":", so ":utils" refers to the top-level "utils" project.) + implementation(project(":utils")) +} + +application { + // Define the Fully Qualified Name for the application main class + // (Note that Kotlin compiles `App.kt` to a class with FQN `com.example.app.AppKt`.) + mainClass = "org.example.app.AppKt" +} diff --git a/app/src/main/kotlin/main.kt b/app/src/main/kotlin/main.kt new file mode 100644 index 0000000..1bec2e2 --- /dev/null +++ b/app/src/main/kotlin/main.kt @@ -0,0 +1,23 @@ +import model.UserAuthorize +import java.time.LocalDate + +val authorizeList = mutableListOf() +fun main(){ + authorizeList.add(registration()) + authorizeList.forEach { + println(it) + } +} +fun registration(): UserAuthorize { + val userLogin = readlnOrNull() + checkNotNull(userLogin) + require(userLogin.length >= 4){ + "Никнейм должен быть больше 4 символов" + } + return UserAuthorize( + authorizeList.size + 1, + password = "123", + login = userLogin, + lastAuthorizeDate = LocalDate.now() + ) +} \ No newline at end of file diff --git a/app/src/main/kotlin/model/UserAuthorize.kt b/app/src/main/kotlin/model/UserAuthorize.kt new file mode 100644 index 0000000..2bb583c --- /dev/null +++ b/app/src/main/kotlin/model/UserAuthorize.kt @@ -0,0 +1,10 @@ +package model + +import java.time.LocalDate + +data class UserAuthorize( + val userId: Int, + val login: String, + var password: String, + var lastAuthorizeDate: LocalDate +) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..6f476b8 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + // The Kotlin DSL plugin provides a convenient way to develop convention plugins. + // Convention plugins are located in `src/main/kotlin`, with the file extension `.gradle.kts`, + // and are applied in the project's `build.gradle.kts` files as required. + `kotlin-dsl` +} + +kotlin { + jvmToolchain(21) +} + +dependencies { + // Add a dependency on the Kotlin Gradle plugin, so that convention plugins can apply it. + implementation(libs.kotlinGradlePlugin) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..705bfb5 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,17 @@ +dependencyResolutionManagement { + + // Use Maven Central and the Gradle Plugin Portal for resolving dependencies in the shared build logic (`buildSrc`) project. + @Suppress("UnstableApiUsage") + repositories { + mavenCentral() + } + + // Reuse the version catalog from the main build. + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "buildSrc" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts new file mode 100644 index 0000000..d11bbb9 --- /dev/null +++ b/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts @@ -0,0 +1,29 @@ +// The code in this file is a convention plugin - a Gradle mechanism for sharing reusable build logic. +// `buildSrc` is a Gradle-recognized directory and every plugin there will be easily available in the rest of the build. +package buildsrc.convention + +import org.gradle.api.tasks.testing.logging.TestLogEvent + +plugins { + // Apply the Kotlin JVM plugin to add support for Kotlin in JVM projects. + kotlin("jvm") +} + +kotlin { + // Use a specific Java version to make it easier to work in different environments. + jvmToolchain(21) +} + +tasks.withType().configureEach { + // Configure all test Gradle tasks to use JUnitPlatform. + useJUnitPlatform() + + // Log information about all test results, not only the failed ones. + testLogging { + events( + TestLogEvent.FAILED, + TestLogEvent.PASSED, + TestLogEvent.SKIPPED + ) + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..b06a80a --- /dev/null +++ b/gradle.properties @@ -0,0 +1,7 @@ +# Enable the build cache to save time by reusing outputs produced by other successful builds. +# https://docs.gradle.org/current/userguide/build_cache.html +org.gradle.caching=true +# Enable the configuration cache to reuse the build configuration and enable parallel task execution. +# (Note that some plugins may not yet be compatible with the configuration cache.) +# https://docs.gradle.org/current/userguide/configuration_cache.html +org.gradle.configuration-cache=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..9065946 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,22 @@ +# Version catalog is a central place for you to declare and version dependencies +# https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format + +[versions] +kotlin = "2.0.21" +kotlinxDatetime = "0.6.1" +kotlinxSerializationJSON = "1.7.2" +kotlinxCoroutines = "1.8.1" + +[libraries] +kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +kotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" } +kotlinxSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJSON" } +kotlinxCoroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" } + +# Libraries can be bundled together for easier import +[bundles] +kotlinxEcosystem = ["kotlinxDatetime", "kotlinxSerialization", "kotlinxCoroutines"] + +[plugins] +kotlinPluginSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..1824fc7 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,25 @@ +// The settings file is the entry point of every Gradle build. +// Its primary purpose is to define the subprojects. +// It is also used for some aspects of project-wide configuration, like managing plugins, dependencies, etc. +// https://docs.gradle.org/current/userguide/settings_file_basics.html + +dependencyResolutionManagement { + // Use Maven Central as the default repository (where Gradle will download dependencies) in all subprojects. + @Suppress("UnstableApiUsage") + repositories { + mavenCentral() + } +} + +plugins { + // Use the Foojay Toolchains plugin to automatically download JDKs required by subprojects. + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + +// Include the `app` and `utils` subprojects in the build. +// If there are changes in only one of the projects, Gradle will rebuild only the one that has changed. +// Learn more about structuring projects with Gradle - https://docs.gradle.org/8.7/userguide/multi_project_builds.html +include(":app") +include(":utils") + +rootProject.name = "AuthApplication" \ No newline at end of file diff --git a/utils/build.gradle.kts b/utils/build.gradle.kts new file mode 100644 index 0000000..3fb9d6d --- /dev/null +++ b/utils/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + // Apply the shared build logic from a convention plugin. + // The shared code is located in `buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts`. + id("buildsrc.convention.kotlin-jvm") + // Apply Kotlin Serialization plugin from `gradle/libs.versions.toml`. + alias(libs.plugins.kotlinPluginSerialization) +} + +dependencies { + // Apply the kotlinx bundle of dependencies from the version catalog (`gradle/libs.versions.toml`). + implementation(libs.bundles.kotlinxEcosystem) + testImplementation(kotlin("test")) +} \ No newline at end of file