Skip to content

Instantly share code, notes, and snippets.

@sunwei
Last active March 30, 2020 07:58
Show Gist options
  • Save sunwei/cb3d71194de64b023b1dad7bea25d82d to your computer and use it in GitHub Desktop.
Save sunwei/cb3d71194de64b023b1dad7bea25d82d to your computer and use it in GitHub Desktop.
Gradle install GitHub maven package

Take xyz.sunwei:design-pattern:0.1.0 for example - package

build.gradle

plugins {
    id 'java'
    id 'maven'
}

repositories {
    jcenter()
    maven { 
        url "https://maven.pkg.github.com/sunwei/design-patterns-java"
        credentials {
            username = System.getenv("USERNAME") ?: System.getProperty("USERNAME")
            password = System.getenv("PASSWORD") ?: System.getProperty("PASSWORD")
        }
    }
}

dependencies {
    implementation 'xyz.sunwei:design-pattern:0.1.0'
}

gradle.properties

systemProp.USERNAME=<your-github-username>
systemProp.PASSWORD=<your-github-token-with-package-permission>
@sunwei
Copy link
Author

sunwei commented Mar 30, 2020

Example:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import xyz.sunwei.designpattern.pipeline.Pipeline;
import xyz.sunwei.designpattern.pipeline.Stage;


public class ExamplePipeline {
    private static final Logger LOGGER = LoggerFactory.getLogger(ExamplePipeline.class);

    public static class SourceInput {
        public final int int1;
        public final int int2;

        public SourceInput(int int1, int int2) {
            this.int1 = int1;
            this.int2 = int2;
        }
    }

    public static class AddIntegersStage implements Stage<SourceInput, Integer> {
        public Integer process(SourceInput input) {
            Integer output = input.int1 + input.int2;
            LOGGER.info(
                    String.format("Current stage: %s, input is %s of type %s, output is %s, of type %s",
                            AddIntegersStage.class, input.toString(), SourceInput.class, output, Integer.class)
            );
            return output;
        }
    }

    public static class IntToStringStage implements Stage<Integer, String> {
        public String process(Integer input) {
            String output = input.toString();
            LOGGER.info(
                    String.format("Current stage: %s, input is %d of type %s, output is %s, of type %s",
                            IntToStringStage.class, input, Integer.class, output, String.class)
            );
            return output;
        }
    }

    public static void main(String[] args) {
        Pipeline<SourceInput, String> pipeline = new Pipeline<>(new AddIntegersStage())
                .addStage(new IntToStringStage());
        System.out.println(pipeline.execute(new SourceInput(1, 3)));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment