0

I would like to publish some common parts of build.gradle file to be reusable in different projects (using apply from: url_to_file construction). To achieve this I've created a project called gradle-common that contains those common build files, with this build.gradle file:

group 'org.example'
version '0.1.0'

apply plugin: 'maven-publish'

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact source: file('files/first.gradle'), classifier: 'first'
        }
        mavenJava(MavenPublication) {
            artifact source: file('files/second.gradle'), classifier: 'second'
        }
    }
    repositories {
        mavenLocal()
    }
}

Files after publishing in maven repository there are files like:

  • gradle-common-0.1.0-first.gradle
  • gradle-common-0.1.0-second.gradle

And my question is: how can I remove version number from published artifacts and the classfier? For me ideal files would be:

  • first.gradle
  • second.gradle
Piotr Chowaniec
  • 1,160
  • 12
  • 25

1 Answers1

0

There are many different answers to your question, but I think you are trying to create something that a plugin usually does without creating a plugin.

The best way to add functionality to multiple gradle projects is to create a plugin. You can also leverage Rules which this simple tutorial doesn't show, but you can inspect some of the gradle native plugins, such as maven-publish.

To answer your question, it is not possible to publish an artifact to a maven repository without a version. You have to download it with a version (you can use my-artifact:1+ to download the latest) and then strip the version yourself.


I am also wondering how are you planning to include these files to your specific gradle files. You won't be able to use them as dependencies, since the dependency resolution happens after the scripts are read. If you are downloading them somehow before the script runs, then you probably don't need a maven repository for that.

MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
  • 1. I know I need version, but it is twice in the url. After publish I can access file via: https://repository_url/group_name/gradle-common/0.1.0/gradle-common-0.1.0-first.gradle, but I would like to have url like: https://repository_url/group_name/gradle-common/0.1.0/first.gradle 2. My first idea was to put in this file sonarqube plugin configuration - there is some number of properties that must be defined that can be defined one for many projects - there is no need to define them in every build.gradle file – Piotr Chowaniec Feb 10 '17 at 09:51