
Police arrested the 17-year-old in January carrying a military-style rucksack as he tried to gain entry to the building in Greenock, on the west coast of Scotland.
Inside the bag officers found a German-made Glock-type air pistol, ammunition, ball bearings, gas cartridges and aerosol cans, prosecutors said.
The teen had mapped out the building’s interior on his phone.
Investigators also found a list of individuals who had inspired his political beliefs including Hitler, Benito Mussolini and Norwegian mass murderer Anders Behring Breivik.
A search of his home found Hitler’s book “Mein Kampf”, knives and masks as well as instructions and ingredients for the manufacturing of explosives.
The High Court in Glasgow sentenced him after he pleaded guilty to two charges of terrorism, Scotland’s Crown Office said.
The teenager – who cannot be named for legal reasons due to his age – will initially serve his sentence in youth custody before being moved to an adult jail.
He will be supervised for eight years after his release.