Coder Social home page Coder Social logo

aepfli / gradle-gitlab-repositories Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 1.0 230 KB

Handling Maven GitLab dependencies made easy. Define multiple tokens and selectively apply them to repositories, remove the need for repeating Credential handling blocks for different environments.

License: Eclipse Public License 2.0

Groovy 82.76% Java 17.24%
gitlab gradle-plugins hacktoberfest

gradle-gitlab-repositories's People

Contributors

aepfli avatar kleino avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kleino

gradle-gitlab-repositories's Issues

Add flag to disable warning for a maven repository

when defining an upload repository, we are currently allow to add it, only if a token is present. We will issue a warning so the user is aware of this. But eg. if we define an environment variable which is only available on CI, we do not want to show this warning.

I suggest we implement a feature to disable this warning

Gradle Kotlin DSL not working for fetching or uploading

As i was not using the kotlin DSL, just groovy it seems like i missed some errors within the kotlin dsl for fetching too.

Currently we are not able to fetch dependencies via kotlin dsl as the configuration seems to be not working as expected.

First we will enhance the tests to also load some dependencies from gitlab (we will use the files we are uploading) and than we will try to adapt the plugin

How to use this library with Google's new recommended Gradle config?

When creating a new project in Android Studio Bumblebee (2021.1.1 RC 1), the Gradle files have the following structure:

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "My App Name"
include ':app'

build.gradle

plugins {
    id 'com.android.application' version '7.1.0-rc01' apply false
    id 'com.android.library' version '7.1.0-rc01' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.app"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.gms:play-services-location:19.0.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

The important line here is repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) in settings.gradle. It prevents repositories from being added in the build.gradle files, instead requiring them to be set here in settings.gradle.

How should this plugin be added to a project with this configuration?

Improve private token handling

As a user i want to be informed when my token configuration is not secure, or i the token is not valid at all.

By setting up a convention that the name of the token within gradle has to be the same as the name of the token in gitlab, we would allow us to check the token for an expiration date etc.

Furthermore we could add checks if there is a token, and if not, to inform the user to create it, with a direct link

evaluate Handling of repositories

currently we are limited, and need to know, which is the enclosing object to add the repositories to the object.
The API looks like

repositories {
    gitLab.group("id")
}

this is limiting, as we need to know when we initalize the plugin to pass on the extensionAware object, so we can add this.

  1. We could investigate, if we could just return a MavenArtifactRepository, and if it will be picked up. This way it would stay the nice and easy way. But that also means, we loose some ootb functionality.

  2. We could change the api to something like

repositories {
    maven gitLab.group("id")
}

where we just return an action. This would allow us to still be able to rely on the OOTB functionality, and make it easier to apply

  1. We could try to return a DSL object from our method which looks like 2. but with the actual action added. This would allow to keep the current way of adding and makes the whole API really nice and smooth

Gradle Kotlin DSL has issues with gitlab.upload without a delegate

Hey, I'm having difficulties using your awesome looking project.
Regardless of what I'm trying, I can't figure out what I have to put into the owner parameter.
Using Kotlin DSL with this it gives me:

* What went wrong:
Execution failed for task ':publishScripts-engine-apiPublicationToGitLab-Project-XXXXXXXXRepository'.
> Failed to publish publication 'scripts-engine-api' to repository 'GitLab-Project-XXXXXXXX'
   > Could not PUT 'https://gitlab.com/api/v4/projects/XXXXXXXX/packages/maven/REDACTED.jar'. Received status code 401 from server: Unauthorized

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

I'm using the following gradle.kts file:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.5.31"
    id("maven-publish")
    id("at.schrottner.gitlab-repositories") version "0.4.1"
}

repositories {
    mavenCentral()
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
    // Spring
    implementation("org.springframework.boot:spring-boot-autoconfigure:2.5.4")

    // Validation
    implementation("org.hibernate:hibernate-validator:7.0.1.Final")

    // Jackson
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.5")

    // Kotlin
    implementation(kotlin("reflect"))
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "${JavaVersion.VERSION_11}"
    }
}

tasks.withType<Jar> {
    manifest {
        attributes("Implementation-Title" to project.name, "Implementation-Version" to "${project.version}")
    }
    archiveFileName.set("api.jar")
}

gitLab {
    val gitLabPrivateToken: String by project
    // jobToken will be applied automatically
    token(at.schrottner.gradle.auths.PrivateToken::class.java) {
        name = "privateToken"
        value = gitLabPrivateToken
    }
}

publishing {
    publications {
        create<MavenPublication>("api"){
            artifact(tasks["jar"])
        }
    }

    repositories {
        maven(gitLab.upload(this,"XXXXXXXX"))
    }
}

How to specify custom Gitlab URL?

If I were using a private/custom intallation of Gitlab, how do I configure the plugin to change the URL from gitlab.com to gitlab.example.com?

Option to not automatically add repository to all projects at 'apply'

hi,

when applying the plugin in settings.gradle, the applyProjects method automatically adds the GitLab repo to all projects via gradle.beforeProject and further project.repositories.maven.

This can be convenient, but also means that when entering the repositories block in build.gradle and adding more repos like mavenCentral, they are behind the GitLab repo in the repositories list. As Gradle checks repositories for dependencies in the order the repos are added, it will search for all dependencies in the added GitLab repo before looking them up in the central maven repo.

Since only a small part of our dependencies are actually in the private repo, it would be better to check mavenCentral beforehand.

An idea would be adding the possibillity to choose if the GitLab repo should be added to all projecs by only applying the plugin, as it happens now. If preferred not to, the repo can still be added to a project via maven gitLab.group('123456') { name = "gitlabgroup" } in the repositories block in the build.gradle. This would allow us to sort the repositories in the way we would like them to be checked.

My current workaround for this is adding the following code block to the settings.gradle file, to add one or more repos before the plugin is applied.

gradle.beforeProject { project ->
  project.repositories {
    mavenCentral()
  }
}

apply plugin: 'at.schrottner.gitlab-repositories'

Improve Kotlin DSL Support

The gitlab extension cannot directly be used in build.gradle.kts files, configure<>() must be used. also the dls function which get a class type as argument should support kotlin reified type parameter.

Support configuring repositories in allprojects and subprojects blocks

I want to configure gitlab repositories for all subprojects and therefore use the subprojects in my root gradle.build.kts file. I applied the plugin in the settings.gradle.kts file using the plugins block:

plugins {
    id("at.schrottner.gitlab-repositories") version "0.5.0"
}

because I want to apply my own gradle plugin, which is hosted in a gitlab repository and therefore the gradle-gitlab-repositories must already be applied before the buildscript block of the root gradle build file is evaluated.

If I use val gitLab = the<at.schrottner.gradle.GitlabRepositoriesExtension>() to access the extension in the subprojects block I get Extension of type 'GitlabRepositoriesExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension]. If I also apply the plugins in the subprojects block, I get Cannot add extension with name 'gitLab', as there is an extension already registered with that name..

Unsupported Media Type error on publish

`> Task :publishCommercePublicationToGitLabRepository FAILED
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':publishCommercePublicationToGitLabRepository'.

Failed to publish publication 'Commerce' to repository 'GitLab'
Could not PUT 'someNiceUrl/3.7.0-SNAPSHOT/maven-metadata.xml'. Received status code 415 from server: Unsupported Media Type

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  • Get more help at https://help.gradle.org`

Good luck fixing :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.