Skip to content

Commit

Permalink
Merge pull request #13587 from gradle/vv/use-optional-credentials
Browse files Browse the repository at this point in the history
Mark credentials as Optional in ivy and maven repositories
  • Loading branch information
big-guy committed Jun 25, 2020
2 parents 72e8893 + d31fc7e commit c105ee5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.gradle.api.publish.ivy.internal.publisher.IvyPublisher;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.artifacts.repositories.AuthenticationSupportedInternal;
Expand All @@ -44,12 +45,9 @@
*/
public class PublishToIvyRepository extends DefaultTask {

private static final Credentials NO_CREDENTIALS = new Credentials() {
};

private IvyPublicationInternal publication;
private IvyArtifactRepository repository;
private final Property<Credentials> credentials = getProject().getObjects().property(Credentials.class).convention(NO_CREDENTIALS);
private final Property<Credentials> credentials = getProject().getObjects().property(Credentials.class);

public PublishToIvyRepository() {

Expand Down Expand Up @@ -118,6 +116,7 @@ public IvyArtifactRepository getRepository() {
}

@Input
@Optional
Property<Credentials> getCredentials() {
return credentials;
}
Expand All @@ -129,7 +128,7 @@ Property<Credentials> getCredentials() {
*/
public void setRepository(IvyArtifactRepository repository) {
this.repository = repository;
this.credentials.set(((AuthenticationSupportedInternal) repository).getConfiguredCredentials().orElse(NO_CREDENTIALS));
this.credentials.set(((AuthenticationSupportedInternal) repository).getConfiguredCredentials());
}

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.publish.maven.internal.publisher.ValidatingMavenPublisher;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.artifacts.repositories.AuthenticationSupportedInternal;
import org.gradle.internal.serialization.Cached;
Expand All @@ -48,10 +49,7 @@ public class PublishToMavenRepository extends AbstractPublishToMaven {
private final Transient.Var<MavenArtifactRepository> repository = varOf();
private final Cached<PublishSpec> spec = Cached.of(this::computeSpec);

private static final Credentials NO_CREDENTIALS = new Credentials() {
};

private final Property<Credentials> credentials = getProject().getObjects().property(Credentials.class).convention(NO_CREDENTIALS);
private final Property<Credentials> credentials = getProject().getObjects().property(Credentials.class);

/**
* The repository to publish to.
Expand All @@ -65,6 +63,7 @@ public MavenArtifactRepository getRepository() {
}

@Input
@Optional
Property<Credentials> getCredentials() {
return credentials;
}
Expand All @@ -76,7 +75,7 @@ Property<Credentials> getCredentials() {
*/
public void setRepository(MavenArtifactRepository repository) {
this.repository.set(repository);
this.credentials.set(((AuthenticationSupportedInternal) repository).getConfiguredCredentials().orElse(NO_CREDENTIALS));
this.credentials.set(((AuthenticationSupportedInternal) repository).getConfiguredCredentials());
}

@TaskAction
Expand Down

0 comments on commit c105ee5

Please sign in to comment.