From shipyard to industrial park — and now farm.

The Brooklyn Navy Yard is taking “going green” to heart, opening a 45,000-square-foot rooftop farm to supply local restaurants, shops and foodies with fresh, organic produce.

Brooklyn Grange — which, oddly, is based in Long Island City, Queens — is expanding the operations of its first-ever Big Apple rooftop produce garden by opening a new open-air farm atop a Navy Yard building near Flushing Avenue and Cumberland Street.

The site was once used for manufacturing by the military but is now part of the city-run industrial park.

“We were looking to be creative, and we found a perfect use for this underutilized roof,” said Andrew Kimball, head of the city’s Brooklyn Navy Yard Development Corp., which oversees the industrial park and its 275 business tenants.

Ben Flanner, Brooklyn Grange’s co-founder and head farmer, said the company is “very excited” to be expanding into the borough it’s named after. He said the roof “will be covered in a lightweight soil about a foot deep with almost every square foot used to grow fruits and vegetables.”

The roof will include an enclosed greenhouse, and the open-air area won’t be in operation during winter months.

Flanner said the company is planning to host a regular “Farmer’s Market” outside the Navy Yard gates on Flushing Avenue. The farm will also provide produce and other ingredients for several businesses that operate at the industrial park, including Kings County Distillery.

About 10,000 seedlings have been planted at the Long Island City farm and will be replanted at the Navy Yard.

The project is being funded with a $592,730 grant in start-up costs by the city’s Department of Environmental Protection because the farm is expected to soak up enough rain to keep more than 1 million gallons of sewage out of the East River per year.

The Brooklyn Navy Yard Development Corp. and Brooklyn Grange each contributed $310,000 in matching funds.

The new farm is expected to open in mid-May.