Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom maven repositories with credentials #997

Open
tgeens opened this issue Sep 5, 2019 · 5 comments
Open

Add support for custom maven repositories with credentials #997

tgeens opened this issue Sep 5, 2019 · 5 comments

Comments

@tgeens
Copy link
Contributor

tgeens commented Sep 5, 2019

In our custom instance we would like to add a maven repository which requires credentials.

For maven projects, this works because the user can define the credentials in ~/.m2/settings.xml while referencing the maven repository-id.

For gradle projects this doesn't work. The gradle-way to accomplish this, looks like this:

maven {
       url 'https://artifacts.mycompany.com/snapshots'
       credentials {
                username property("com.mycompany.artifacts.username")
                password property("com.mycompany.artifacts.password")
        }
}

This is currently not supported by Initializr.

@tgeens
Copy link
Contributor Author

tgeens commented Sep 5, 2019

My proposal:

  1. Add a credentials field to the MavenRepository model. The type would be a MavenRepositoryCredentials object with username & password fields. (Or a key-value map-like object, which would facilitate extending this to non-basic-auth later on.)

2a. The maven-build-writer can ignore the credentials field - just like the gradle-build-writer is ignoring the name and snapshotsEnabled fields from MavenRepository

2b. The gradle-build-writer can check if there are (non-default) credentials provided and write those to the build.gradle if necessary. Currently the gradle-build-writer can only write repositories on a single line (like maven { url 'https://repo.spring.io/snapshot' }).

To support a representation which includes credentials info, the implementation of GradleBuildWriter#writeRepositories should be updated and the method signature

protected abstract String repositoryAsString(MavenRepository repository)

should change into something that can (optionally) write multi-line repository information, like

protected void writeRepository(IndentingWriter writer, MavenRepository repository)

@otheriault
Copy link

Since it it not mentioned explicitly in this issue, I think it would be equally valid to support maven repository credentials in the settings.gradle#pluginManagement like this:

pluginManagement {
    repositories{
        maven {
            url 'https://artifacts.mycompany.com/snapshots'
               credentials {
                  username property("com.mycompany.artifacts.username")
                  password property("com.mycompany.artifacts.password")
              }
        }
        gradlePluginPortal()
    }
}

There is also limited extensibility here since the GradleSettingsWriter#repositoryAsString is private as well as most of the writeX methods.

@wilkinsona wilkinsona self-assigned this Nov 17, 2020
@wilkinsona
Copy link
Contributor

For Gradle 6.6 and later, we can use their new credential handling support. For earlier versions of Gradle we can mimic that support by writing out property lookups with the property names derived from the repository's name. This will allow common configuration to be written out in different ways by version-specific writers.

@srinivasvsk
Copy link

will this be addressed at some point?

@wilkinsona
Copy link
Contributor

We hope to address it at some point, that's why the issue has not be closed. We don't have any firm plans or a date in mind at the moment, however.

@wilkinsona wilkinsona removed their assignment Jun 14, 2022
sayeedap pushed a commit to sayeedap/initializr that referenced this issue Sep 16, 2022
added jackson annotations on generated interface for deserialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants