labs / tiddlers / content / labs / lab02 / _Labs_02_Create the

You should remember from last week's lab that we can create a project by adding a build.gradle file to a folder and opening that folder in NetBeans. This is our preferred way of creating projects since it means that we don't have to deal with the annoying multi-projects that we get if we use NetBeans to create the project.

  1. Locate the lab02_git folder that was created when you cloned the repository using the system file manager.

  2. Create a new file inside the lab02_git named build.gradle. You can create a new file by right clicking the background and using <

    Empty File">>.

  3. Copy the contents of <> into the file. This is the same build.gradle script that you saw last week, but with two additions:

    • The repositories section tells Gradle which repositories to use to download any library dependencies that are required. Maven central is the primary library repository for Java.

    • The run section tells Gradle to pass the stream through to the application. By default Gradle does not do this which means that code that tries to read input from the console will not work. It is not often that we need to use the stream, but if you are working on the Java review exercises then you will need to do this for a couple of the exercises.

  4. Save the file.

  5. Open the lab02_git folder in NetBeans using <

    Open Project">>.

  6. If you see a dialog appear that is warning you about problems with the project, just close it --- you can check the box on the dialog to prevent it from showing you this dialog in the future. The so called 'problem' is that the project needs a priming build. NetBeans will show a little warning icon over the project until the priming build is done.

  7. If you haven't done so already, build the project to fix the warning.

  8. Run the createMissingSourceDirs task by selecting the project in the projects pane and then double clicking the task in the navigator pane.

  9. Run the createGitIgnore task to add a .gitignore file to the repository. We only briefly discussed the .gitignore file in last week's lab. Any files or folders that are listed in this file will be ignored by Git.

    Many of the problems that we see students having with Git are caused by the student committing some build output or other rubbish such as Gradle caches to their repository. Build output and caches change very frequently which makes it easy for merge conflicts to occur if these files are part of your repository. Another common source of problems is the DS_Store files that Macs like to leave all over the place --- again because these files change frequently which can cause merge conflicts.

    We also have size limits on push operations on the GitBucket server. This is to stop students from accidentally pushing their entire home folder into a repository (it is surprisingly easy to accidentally create a repository in the root of your home folder). The limit is currently 20MB which is more than enough considering your total repository size at the end of the semester will generally be less than 1MB if you keep the rubbish out of it.

    <> Since the file starts with a . it is considered to be a system file and will be hidden by default in most file managers. You can toggle the file manager setting to show hidden files (< h">> in the Linux lab), or you can use the files pane in NetBeans which does not hide these files.

    Open the .gitignore file in the files pane in NetBeans to take a look. As mentioned, this is a list of all of the files and folders that should be ignored by Git.

    When you commit, you are presented with a list of files that will be committed. It is always worth taking a quick look at the list to see if there is anything in the list that you don't want to be committed --- if so, cancel the commit and add the unwanted files to the .gitignore file.

  10. Run the wrapper task to add the Gradle wrapper to the project.

  11. If you don't see the four source directories in the project pane, restart NetBeans. As mentioned last week, this is a glitch that happens with NetBeans when the projects are stored on file servers or file systems that don't properly implement file change notifications.