-
Notifications
You must be signed in to change notification settings - Fork 10
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
Unable to get the plugin to work for repositories within a pluginManagement block #227
Comments
This allowed me to add pluginManagement repositories support for CodeArtifact @TypeChecked
class CodeArtifactPluginRepositoriesPlugin implements Plugin<Settings> {
void apply(Settings settings) {
def gradle = settings.getGradle()
def pluginRepositories = settings.pluginManagement.repositories
SharedFunctions.setupCodeartifactRepositoriesByUrl(gradle, pluginRepositories)
}
} It would be better if this could be baked into the library so that others can profit from it. I don't have a PR because:
@TypeChecked
class CodeArtifactRepositoriesPlugin implements Plugin<Project> {
void apply(Project project) {
def gradle = project.getGradle()
//setupCodeartifactRepositories(project, serviceProvider) <-- magic
SharedFunctions.setupCodeartifactRepositoriesByUrl(gradle, project.repositories)
}
} Other than that the SharedFunctions contains the functions required by both plugins package ai.clarity.codeartifact
import groovy.transform.TypeChecked
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.invocation.Gradle
import org.gradle.api.provider.Provider
@TypeChecked
class SharedFunctions {
static Provider<CodeArtifactToken> codeArtifactTokenProviderFor(Gradle gradle) {
return gradle
.getSharedServices()
.registerIfAbsent('codeartifact-token', CodeArtifactToken.class, {})
}
static void setupCodeartifactRepositoriesByUrl(Gradle gradle, RepositoryHandler repositories) {
configRepositories(repositories, codeArtifactTokenProviderFor(gradle))
}
private static void configRepositories(RepositoryHandler repositories, Provider<CodeArtifactToken> serviceProvider) {
ListIterator it = repositories.listIterator()
while (it.hasNext()) {
def artifactRepository = it.next()
if (artifactRepository instanceof MavenArtifactRepository) {
MavenArtifactRepository mavenRepo = (MavenArtifactRepository) artifactRepository;
URI repoUri = mavenRepo.getUrl()
if (isCodeArtifactUri(repoUri) && areCredentialsEmpty(mavenRepo)) {
String profile = getProfileFromUri(repoUri, getDefaultProfile())
//logger.info('Getting token for {} in profile {}', repoUri.toString(), profile) <-- no logger for Settings
println("Getting token for $repoUri in profile $profile")
String token = serviceProvider.get().getToken(repoUri, profile)
mavenRepo.credentials({
it.username = 'aws'
it.password = token
})
mavenRepo.setUrl(removeProfile(repoUri))
}
}
}
}
private static String getDefaultProfile() {
...
}
private static URI removeProfile(URI uri) {
...
}
private static boolean areCredentialsEmpty(MavenArtifactRepository mavenRepo) {
...
}
private static boolean isCodeArtifactUri(URI uri) {
...
}
private static String getProfileFromUri(URI uri, String defaultValue) {
...
}
} And the gradlePlugin block declares each of them separately gradlePlugin {
plugins {
codeArtifactRepositories {
id = 'ai.clarity.codeartifact.repositories'
implementationClass = 'ai.clarity.codeartifact.CodeArtifactRepositoriesPlugin'
}
codeArtifactPluginRepositories {
id = 'ai.clarity.codeartifact.pluginRepositories'
implementationClass = 'ai.clarity.codeartifact.CodeArtifactPluginRepositoriesPlugin'
}
}
} |
I'm going to submit a PR, with the smallest change possible, as I was unable to refactor effectively in the absence of type checking (some errors only show up at runtime, after publishing the plugin, making the refactoring experience hell). |
Created a PR (#230). Keep what you like and throw the rest away. |
Updated #230 |
Updated PR #230 hopefully for the last time. |
As I don't see any pluginManagement in your README.md, I assume it's not supported.
Are you aware of any such limitation?
This is what I'm trying to do:
As I intend to publish gradle plugins to CodeArtifact, other projects need a way to consume said plugins...
The text was updated successfully, but these errors were encountered: