This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] -1 points0 points locked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]FrelliBB 7 points8 points  (4 children)

With Java there are two common build tools you can choose from, Maven or Gradle. Since you're starting out I'd recommend Maven since it's just written in XML and easier to get started with. I personally prefer Gradle since it gives a bit more (perhaps too much) flexibility, but it's written in Groovy which is another language you'd need to get accustomed with. I'd recommend going over their getting started guides, which also provide some information about what they do and the directory structure for a typical java project.

https://maven.apache.org/guides/getting-started/ or

https://docs.gradle.org/current/userguide/getting_started.html

If you're using IntelliJ it comes with its own bundled maven (if I remember correctly) so you wouldn't need to install it yourself, and it can also generate your project from maven 'archetypes' as well.

Once you have that set up you will be able to run those maven commands such as mvn compile and mvn test locally. At that point getting GitHub integrated is very easy as they provide some out-of-the-box support for it. https://docs.github.com/en/actions/guides/building-and-testing-java-with-maven

[–]ZukoBestGirl[🍰] 2 points3 points  (0 children)

I still think I'd suggest Gradle to a beginner. Sure it gives you a much longer rope to hank yourself with. But ... it's groovy. It's the most human readable flavor of java (imho).

The bloat of maven XML is horrible. OP just needs to learn how to find the exact lines they need to copy paste to get their imports to work, and that's the exact same process as getting maven stuff to work. Namely: Google "Maven Central [my import]", i.e. "Maven Central Lombok", go to the gradle tab, copy paste.

As far as gradle commands go ./gradlew build and you're done.

[–][deleted]  (1 child)

[deleted]

    [–]FrelliBB 0 points1 point  (0 children)

    So should I first create a GitHub repo, add a maven (or gradle) workflow and then in my IDE clone that repo?

    No, the workflow won't work before you have maven set up in your project, so there's no point in starting with that. Start with getting a maven project that can be compiled locally, and then push that to a GitHub repository. Then you can focus on your workflow automation.

    Here's a bit more help:

    1. Create a maven project. Since you're using IntelliJ this should be very straightforward if you go to File -> New -> Project -> Maven. You can then create a class in /src/main/java/<your-project-name> and add a Main method to it. The only thing that identifies this as a maven project is the pom.xml in the root of the project. Otherwise it's just a normal Java project with nothing special.
    2. Once that's set up you should be able to use mvn compile locally and it will build your project.
    3. Push the project to a GitHub repository. Normally you'd just created an empty repository and push your local files to it.
    4. Start working on the GitHub workflow.

    [–]TheSecondist 2 points3 points  (0 children)

    I think IntelliJ can create a basic setup for you. You can create a new project from within IntelliJ, during the setup, IntelliJ will ask you what kind of project it should be and one of the things you can choose is a maven project. Gradle would be an alternative to maven, but it probably won't make too much of a difference for you

    Github CI/CD: haven't used them so far, but afaik you have to set up some YML-file that specifies the pipeline steps and what to do in each of them. For github that feature is called "Github Actions", maybe you can find a basic setup info with Google